Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Can delphi case statement variables use strings?
Can delphi case statement variables use strings?
Case statement can only be used for ordinal type, that is, 1) integer; 2) Character type; 3) Enumeration types.

If you want to use it for strings, you can take several alternatives:

Use TStringList. Let's start with one alternative string after another, shall we? Add it in and call its IndexOf method;

If the nth character (n should be a constant) of your alternatives is different from each other, then you can uniquely identify your string by taking out this character;

First, all alternatives are declared as an enumeration value, and then we can use the case statement as long as we convert the string we are looking for into an enumeration. For example: type tmystrsel = (Beijing, Tianjin, Shanghai, Chongqing). However, if you choose a variable name naming rule that does not conform to Delphi (such as' AK-47' or Chinese). ), cannot be declared as an enumeration type, and cannot use this method.