Scalabium Software |
|
Knowledge for your independence'. | |
Home Delphi and C++Builder tips |
#126: How can I decode http/url value? |
|
Everybody, who wrote some tools for web, know that urls/filename/script parameters etc are encoded (contains the %xx substrings). For example, Of course, in code you must decode a value in "real" value. The algorithm is easiest - after % character the next 2 positions are decimal code of character. But also for this task you can use the HTTPEncode function from HttpApp unit: function HTTPEncode(const AStr: String): String; const NoConversion = ['A'..'Z','a'..'z','*','@','.','_','-']; var Sp, Rp: PChar; begin SetLength(Result, Length(AStr) * 3); Sp := PChar(AStr); Rp := PChar(Result); while Sp^ <> #0 do begin if Sp^ in NoConversion then Rp^ := Sp^ else if Sp^ = ' ' then Rp^ := '+' else begin FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]); Inc(Rp,2); end; Inc(Rp); Inc(Sp); end; SetLength(Result, Rp - PChar(Result)); end;
|
|
Copyright© 1998-2024, Scalabium
Software. All rights reserved. |