Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert string to char or how to get ASCII-Code from a string

3,858 views
Skip to first unread message

Michael Sander

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to
Hi,
this is rather a newbie question but I couldn´t find any solution for this:

I got a string like str='A' and I would like to get the ASCII-code from it.
It works fine with char='A' and Integer(char), but i just don´t know how to
convert it.

Michael Sander

Johannes Berg

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to
> I got a string like str='A' and I would like to get the ASCII-code from it.
> It works fine with char='A' and Integer(char), but i just don´t know how to
> convert it.

var str : string;
begin
str:='A';
showmessage(inttostr(ord(str[1])));
end;

johannes
--
Please reply in this newsgroup only
- SIP solutions -
http://www.sipsolutions.de/

Howard Moon

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to
Just to expand on the example:

1. str[1] returns the first character (as type Char) from the string.
2. Ord( a ) returns the ASCII value of the character a.
3. IntToStr( x ) returns the string representation of the integer value x.

So, IntToStr( Ord( str[1] ) ) returns the string representation of the ASCII
code for the first character of str.
-Howard


0 new messages