Reputation: 6061
For URL-Encoding/Decoding, it has been suggested to use TNetEncoding
from Delphi XE7 upwards.
So in Delphi XE8 i use this code for example:
uses
System.NetEncoding;
...
edtEncodedURL.Text := TNetEncoding.URL.Encode('SetFont(''Arial'',15)');
which gives the following result:
SetFont('Arial'%2C15)
However, this does not encode the single quote characters, as you can see from the example above.
Moreover, at W3Schools.com HTML URL Encoding Reference, in the "Try It Yourself" section, the string SetFont('Arial',15)
is URL-encoded to:
SetFont%28%27Arial%27%2C15%29
So is there a way to URL-encode also the single quote characters in Delphi XE8?
Upvotes: 1
Views: 5195
Reputation: 6061
This seems to work for the purpose asked in the question:
uses
System.NetEncoding,
REST.Utils;
procedure TForm1.btnURLEncodeClick(Sender: TObject);
begin
edtEncodedURL.Text := REST.Utils.URIEncode(edtOriginalURL.Text);
end;
procedure TForm1.btnURLDecodeClick(Sender: TObject);
begin
edtDecodedURL.Text := TNetEncoding.URL.Decode(edtEncodedURL.Text);
end;
Upvotes: 5