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

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.


Since string became 0-based on mobile platforms, there is also an always-safe way to get a char from single-character string.

myString[Low(myString)]

Since delphi became cross-platform I would use 0-based string access using TStringHelper class out of unit System.SysUtils:

case MyString.Chars(0) Of
// ...
end;