Mega Code Archive

 
Categories / Delphi / Strings
 

How to send compless strings (all 256 ASCII) to an ASP page

Title: How to send compless strings (all 256 ASCII) to an ASP page Question: Ever needed to send compless strings, that contains ASCII values that will be truncated from the HTTP protocol, to an ASP page? I did, but I found a solution and there it's.. Answer: Just convert the complete string to a hexadecimal value with this function... Function CharsToPrintable( What : String ) : String; Var IdX : Integer; tmpStr, outStr : String; Begin Result := ''; outStr := ''; tmpStr := What; For IdX := 1 To Length( tmpStr ) Do outStr := outStr + IntToHex( StrToInt( tmpStr[ IdX ] ), 2 ); Result := outStr; End; ..and then reconvert it to the original string, taking 2 chars at time and calculating the original ASCII value (byte) with this ASP code (works correctly in Visual Basic, but I have not yet tested with ASP (will try soon)): Private Function GetFromHexValue(Da As String) As String Dim Ai As Integer Dim Bi As Integer If IsNumeric(Left(Da, 1)) Then Ai = CInt(Left(Da, 1)) Else Ai = Asc(UCase(Left(Da, 1))) - 65 End If If IsNumeric(Right(Da, 1)) Then Bi = CInt(Right(Da, 1)) Else Bi = Asc(UCase(Right(Da, 1))) - 55 End If GetFromHexValue = Chr(Ai * 16 + Bi) End Function ...and... Dim X As Integer Dim A As String Dim Inputed As String Inputed = "" For X = 1 To Len(Request.QueryString("MyString")) Step 2 If X Len(Request.QueryString("MyString")) Then Exit For A = Mid(Request.QueryString("MyString"), X, 2) Inputed = Inputed + GetFromHexValue(A) Next X Response.Write Inputed