Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert one character from a string to a char in delphi

I have a string, from which I want to extract one character that is needed to be used in a Case statement. The thing is the Case only takes Char values and not string values. So how do I convert a single string character to a char?

like image 224
Japster Avatar asked Jun 01 '12 16:06

Japster


1 Answers

Use the string as a character array (1-based), and use the index of the character you want to use in the case statement. For instance, if you want to use the first character:

case MyString[1] Of
// ...
end;

NB make sure you check the the string is of at least that length before you use the subscript, or you'll get an access violation.

like image 136
Tony Hopkinson Avatar answered Nov 15 '22 08:11

Tony Hopkinson