Integer <> Character Casts

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Integer <> Character Casts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:14 pm

by David Mitchell >> Thu, 6 May 1999 2:11:43 GMT

Here's a tip I discovered when playing around with binary files:

If you have a character like so:

vars
chr : Character;

and you say :

i := chr.Integer;

then i gets the ASCII value for chr. This also works the other way. So if i is 65 then

chr := i.Character;

makes chr = 'A'.

Neats huh?

David.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Integer <> Character Casts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:14 pm

by Kevin Alcock >> Thu, 6 May 1999 3:30:07 GMT

Also try i := 321;

even cooler

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Integer <> Character Casts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:14 pm

by David Mitchell >> Thu, 6 May 1999 5:13:34 GMT

What type areyou talking about for i? I'm meaning i as an Integer. How is i:=321; cool?

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Integer <> Character Casts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:14 pm

by Kevin Alcock >> Thu, 6 May 1999 21:52:21 GMT

vars
i : Integer;begin

i := 321;
write i.Character;
end;

result is...
A

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Integer <> Character Casts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:14 pm

by Robert Barr >> Fri, 7 May 1999 4:00:47 GMT

write 577.Character; // result is...A - double cool
write 629057.Character; // result is...A - positively chilly
(ANSI only)

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Integer <> Character Casts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:14 pm

by John Porter >> Fri, 26 Nov 1999 3:55:24 GMT

Now for something that is actually useful...

vars
chr:Character;begin

chr:="A";
write (chr.Integer+1).Character;
end;

..... and the result is

B

Can be used for selecting the next letter: "fileA", "fileB"...

Cheers,
John P


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 3 guests

cron