Link to home
Start Free TrialLog in
Avatar of bjornborg
bjornborg

asked on

Convert String to Char?

This is probably very easy, but still:

I would like to return the ord() value of a character:

ord('c') returns 99

but if I try to extract the letter from a string like this:
 Mystring := midstr(strLongString,nbrStartPos,1); //e.g 'c'

and then want to use the function

 nbrThatItIs := ord(Mystring);

I get an error because Mystring is "string" and I need to use Char.

So: How do I best convert my string to char?

ASKER CERTIFIED SOLUTION
Avatar of edey
edey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bugroger
bugroger

Edey, i think you mean "the value of the _second_ char
in a string" and the _third_ in a PChar. :-)

s = '123';
 
ord(s[2]);         -> "2"
ord(PChar(s)[2]);  -> "3"
Umm, yeah, that's right! Sorry about the little mixup :).

GL
Mike