2005. január 21., péntek
Send compless strings (all 256 ASCII) to an ASP page
Problem/Question/Abstract:
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
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése