+ 1
How to create switch for strings?
6 Answers
+ 2
Good question, it stumped me. But, from my short search, there is no such thing. At least, not an easy way to implent it.
+ 2
Switches don't work with strings or floating point numbers.
You are limited to integers, characters, booleans and enumerations.
+ 1
Well you aren't able to do it I'm afraid.
For strings, use else-if,
if (str == "Hi") { }
else if (str == "Hello") { }
//if necessary, add more else-if
else { }
0
I guess its only compatible with intergers?
0
I need it because I want to create some like command line( in OS Windows).
I can use "if", but "switch" is more compact.
0
i never really thought of this, very interesting