(Delphi ActiveX) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
s: WideString;
sb: TChilkatStringBuilder;
success: Integer;
sEncoded: WideString;
numReplaced: Integer;
begin
// To URL encoding a string:
s := 'Why a > b?';
sb := TChilkatStringBuilder.Create(Self);
success := sb.Append(s);
// URL encode the string.
sb.Encode('url','utf-8');
// Show the URL encoded string:
sEncoded := sb.GetAsString();
Memo1.Lines.Add(sEncoded);
// The result is: Why%20a%20%3E%20b%3F
// If you prefer "+" instead of "%20" for SPACE chars:
numReplaced := sb.Replace('%20','+');
Memo1.Lines.Add(sb.GetAsString());
// Output is: Why+a+%3E+b%3F
// To decode:
sb.Decode('url','utf-8');
Memo1.Lines.Add(sb.GetAsString());
// Result is: Why a > b?
end;
|