• Status: Solved
• Priority: Medium
• Security: Public
• Views: 693

# convert string to URL validated string?

Has someone function/procedure for converting strings to URL validated text?

for example to convert

http://www.somesite.com is "the best"

to

http%3A%2F%2Fwww.somesite.com+is+%22the+best%22

0
kzdown
1 Solution

Commented:
Hi,

do you mean something like that?:

Function StringToUrl(S : String) : String;
VAR
z : Integer;
Begin
Result := '';
For z := 1 to Length(s) do
Begin
Case s[z] Of
' '  : Result := Result + '+';
':'  : Result := Result + '%' + IntToHex(Ord(':'), 2);
'/'  : Result := Result + '%' + IntToHex(Ord('/'), 2);
'"'  : Result := Result + '%' + IntToHex(Ord('"'), 2);
else   Result := Result + s[z];
End;
End;
End;

Function URLToString(Url : String) : String;
VAR
z      : Integer;
hexStr : String;
Begin
Result := '';
z := 1;
While z <= Length(Url) do
Begin
Case URL[z] Of
'+'  : Result := Result + ' ';
'%'  : Begin
Result := Result + Chr(StrToInt('\$' + URL[z +1] + URL[z +2]));
Inc(z, 2);
End;
else   Result := Result + URL[z];
End;
Inc(z);
End;
End;

GL
Bug
0

Author Commented:
yes. exactly what i needed.
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.