Sample code for 30+ languages & platforms
Delphi DLL

URL Encoding and Decoding

See more Encryption Examples

Demonstrates URL encoding and decoding.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringBuilder;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
s: PWideChar;
sb: HCkStringBuilder;
sEncoded: PWideChar;
numReplaced: Integer;

begin
success := False;

// To URL encoding a string:
s := 'Why a > b?';

sb := CkStringBuilder_Create();
success := CkStringBuilder_Append(sb,s);

// URL encode the string.
CkStringBuilder_Encode(sb,'url','utf-8');

// Show the URL encoded string:
sEncoded := CkStringBuilder__getAsString(sb);
Memo1.Lines.Add(sEncoded);

// The result is:  Why%20a%20%3E%20b%3F

// If you prefer "+" instead of "%20" for SPACE chars:
numReplaced := CkStringBuilder_Replace(sb,'%20','+');
Memo1.Lines.Add(CkStringBuilder__getAsString(sb));

// Output is:   Why+a+%3E+b%3F

// To decode:
CkStringBuilder_Decode(sb,'url','utf-8');
Memo1.Lines.Add(CkStringBuilder__getAsString(sb));

// Result is: Why a > b?

CkStringBuilder_Dispose(sb);

end;