//***************************************************************************************** // Copyright (c) 2000 Michael Kurz // All rights reserved. // If you want to use this source in your applications conatct: // // $FileName : mStrConv.Pkg // $ProjectName : Sahred Methods and Functions // $Author : Michael Kurz // $Created : 01-25-2001 @ 19:00 // // Contents: // Functions for converting strings to a string with its ASCII values and back. // // // $Rev History // //***************************************************************************************** // Flips a string Left-Right Function FlipStrLR Global String sStr Returns String Integer iC iL String sRet Move (Length(sStr)) To iL For iC From 1 To iL Move (Append(Mid(sStr,1,iC),sRet)) To sRet End Function_Return sRet End_Function // Converts a String to Ascii Code Function ConvertBuffToAscii Global String sBuff Returns String String sCh sRet Integer iCh iC iLength Move (Length(sBuff)) To iLength For iC From 1 To iLength Move (Mid(sBuff,1,iC)) To sCh Move (Ascii(sCh)) To sCh Move (Right(Append("000",sCh),3)) To sCh Append sRet sCh End Function_Return sRet End_Function // Converts a String from Ascii back to str. Function ConvertAsciiToBuff Global String sBuff Returns String String sCh sRet Integer iCh iC iLength Move (Length(sBuff)) To iLength For iC From 1 To iLength Move (Mid(sBuff,3,iC)) To iCh Append sRet (Character(iCh)) Move (iC+2) To iC // 1+2=3 End Function_Return sRet End_Function // Converts one Digit from Decimal to Hex. Function IntToHexDigit Global Integer iInt Returns String If iInt Lt 0 Function_Return 0 If iInt Lt 10 Function_Return iInt If iInt Eq 10 Function_Return "A" If iInt Eq 11 Function_Return "B" If iInt Eq 12 Function_Return "C" If iInt Eq 13 Function_Return "D" If iInt Eq 14 Function_Return "E" If iInt Eq 15 Function_Return "F" End_Function // Converts one Digit from Decimal to Hex. Function HexToIntDigit Global String sHEX Returns Integer If sHex Eq "F" Function_Return 15 If sHex Eq "E" Function_Return 14 If sHex Eq "D" Function_Return 13 If sHex Eq "C" Function_Return 12 If sHex Eq "B" Function_Return 11 If sHex Eq "A" Function_Return 10 Function_Return sHex End_Function #IFNDEF GET_IntToHex // Converts a decimal value (0-255) Function IntToHex Global Integer iInt Returns String Integer iL iH String sL sH sRet Move (iInt/16) To iH Move (Mod(iInt,16)) To iL Append sRet (IntToHexDigit(iH)) (IntToHexDigit(iL)) Function_Return sRet End_Function #ENDIF // Converts a hex value to decimal (0-255) Function HexToInt Global String sHex Returns Integer Function_Return ((HexToIntDigit(Left(sHex,1))*16)+(HexToIntDigit(Right(sHex,1)))) End_Function // Converts a character to an Ascii value in Hex Function AsciiHex Global String sCH Returns String Function_Return (IntToHex(Ascii(sCH))) End_Function // Converts a ascii hex value to a character. Function CharacterHex Global String sHex Returns String Function_Return (Character(HexToInt(sHex))) End_Function // Converts a String to Ascii Code Function ConvertBuffToAsciiHex Global String sBuff Returns String String sCh sRet Integer iCh iC iLength Move (Length(sBuff)) To iLength For iC From 1 To iLength Move (Mid(sBuff,1,iC)) To sCh Move (AsciiHex(sCh)) To sCh Append sRet sCh End Function_Return sRet End_Function // Converts a String from Ascii back to str. Function ConvertAsciiToBuffHex Global String sBuff Returns String String sCh sRet Integer iCh iC iLength Move (Length(sBuff)) To iLength For iC From 1 To iLength Move (Mid(sBuff,2,iC)) To sCh Append sRet (CharacterHex(sCh)) Move (iC+1) To iC // 1+1=2 End Function_Return sRet End_Function // Converts some special characters in a string. Function fsConvertString Global String sStr Returns String String sCR Append sCR (Character(13)) (Character(10)) Move (Replaces("\n",sStr,sCR)) To sStr Move (Replaces("\t",sStr,Character(9))) To sStr Move (Replaces("\C34",sStr,Character(34))) To sStr Function_Return sStr End_Function