URL encoding: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 546: | Line 546: | ||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
<pre>http%3A%2F%2Ffoo%20bar%2F</pre> |
<pre>http%3A%2F%2Ffoo%20bar%2F</pre> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
function EncodeURL(URL: string): string; |
|||
var I: integer; |
|||
begin |
|||
Result:=''; |
|||
for I:=1 to Length(URL) do |
|||
if URL[I] in ['0'..'9', 'A'..'Z', 'a'..'z'] then Result:=Result+URL[I] |
|||
else Result:=Result+'%'+IntToHex(byte(URL[I]),2); |
|||
end; |
|||
procedure EncodeAndShowURL(Memo: TMemo; URL: string); |
|||
var ES: string; |
|||
begin |
|||
Memo.Lines.Add('Unencoded URL: '+URL); |
|||
ES:=EncodeURL(URL); |
|||
Memo.Lines.Add('Encoded URL: '+ES); |
|||
Memo.Lines.Add(''); |
|||
end; |
|||
procedure ShowEncodedURLs(Memo: TMemo); |
|||
begin |
|||
EncodeAndShowURL(Memo,'http://foo bar/'); |
|||
EncodeAndShowURL(Memo,'https://rosettacode.org/wiki/URL_encoding'); |
|||
EncodeAndShowURL(Memo,'https://en.wikipedia.org/wiki/Pikes_Peak_granite'); |
|||
end; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Unencoded URL: http://foo bar/ |
|||
Encoded URL: http%3A%2F%2Ffoo%20bar%2F |
|||
Unencoded URL: https://rosettacode.org/wiki/URL_encoding |
|||
Encoded URL: https%3A%2F%2Frosettacode%2Eorg%2Fwiki%2FURL%5Fencoding |
|||
Unencoded URL: https://en.wikipedia.org/wiki/Pikes_Peak_granite |
|||
Encoded URL: https%3A%2F%2Fen%2Ewikipedia%2Eorg%2Fwiki%2FPikes%5FPeak%5Fgranite |
|||
Elapsed Time: 11.734 ms. |
|||
</pre> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |