Board index » off-topic » Converting hex numbers to ascii characters

Converting hex numbers to ascii characters


2003-07-13 11:56:19 PM
off-topic13
Hello,
I am trying to write a little program to convert
http%3a%2f%2fwww%2ewinxpnews%2ecom%2frd%2frd%2ecfm%3fid%3d030325FA%2dArt%26mid%3d5123889284442989
to
www.winxpnews.com/rd/rd.cfm
I am having trouble getting the hex numbers converted to their ascii
values. ANY help will be much appreciated. If it matters, I am using
TP 7.0
thanks
 
 

Re:Converting hex numbers to ascii characters

On Sun, 13 Jul 2003 17:24:51 +0100, Brian Key
< XXXX@XXXXX.COM >wrote:
Quote
On Sun, 13 Jul 2003 10:56:19 -0500, Raymond Holtzfingeru wrote:

>Hello,
>I am trying to write a little program to convert
>http%3a%2f%2fwww%2ewinxpnews%2ecom%2frd%2frd%2ecfm%3fid%3d030325FA%2dArt%26mid%3d5123889284442989
>to
>www.winxpnews.com/rd/rd.cfm
>I am having trouble getting the hex numbers converted to their ascii
>values. ANY help will be much appreciated. If it matters, I am using
>TP 7.0
>
>thanks

Well, there are probably MUCH tidier ways of doing this...
(the trick is that val will accept and convert either '42' or '$2a')

const
Url='http%3a%2f%2fwww%2ewinxpnews%2ecom%2frd%2frd%2ecfm%3fid%3d030325FA%2dArt%26mid%3d5123889284442989';

var
s,v,i:integer;
h,CvtUrl:string;

begin
i:=1;
CvtUrl:='';
while i <= Length(Url) do
begin
if Url[i] <>'%' then
begin
CvtUrl:=CvtUrl + Url[i];
inc(i)
end
else
begin
h:='$'+Url[i+1] + Url[i+2];
val(h,v,s);
CvtUrl:=CvtUrl + Chr(v);
inc(i,3)
end
end;
writeln('Old: "',Url,'"');
writeln('New: "',CvtUrl,'"')
end.
Brian,
Thank you for the quick reply. This thing works just like I wanted.
I tried to use val(), but I did not know to put the '$' in front of
what I was passing it. Thanks again.
Howard
 

Re:Converting hex numbers to ascii characters

On Sun, 13 Jul 2003 14:49:27 -0500, Raymond Holtzfingeru wrote:
[snips]
Quote
Brian,
Thank you for the quick reply. This thing works just like I wanted.
I tried to use val(), but I did not know to put the '$' in front of
what I was passing it. Thanks again.

Howard
Excellent! I'm very pleased it helped.
--
Brian Key
XXXX@XXXXX.COM
 

{smallsort}