Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

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?

0
bjornborg
Asked:
bjornborg
  • 2
1 Solution
 
edeyCommented:
to get the ord value of the _third_ char in a string, try this:

ord(myString[2]);


GL
Mike
0
 
bugrogerCommented:
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"
0
 
edeyCommented:
Umm, yeah, that's right! Sorry about the little mixup :).

GL
Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now