Scalabium Software

SMExport advertising
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,
http://groups.google.com/groups?q=http%3A%2F%2Fwww.scalabium.com&hl=ru&meta= site%3Dgroups or http://groups.google.com/groups?th=1223ec006df22d25&seekm=3b98e41d_2%40dnews

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;


Published: September 11, 2001

See also
 
Database Information Manager
DBLoad
Viewer for TNEF-files (winmail.dat)
Clarion Viewer
SMReport
Protected Storage Viewer
Excel Reader (dll)
Paradox Viewer
SMExport suite
Word Web-stream
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport/SMImport suites