Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# convert string to URL validated string?

Posted on 2001-08-18
Medium Priority
681 Views

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
Question by:kzdown
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 2

Accepted Solution

bugroger earned 180 total points
ID: 6403187
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 Comment

ID: 6404619
yes. exactly what i needed.
thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…