Uppercase/lowercase?

hi guys!
ok so i have this statement - while(strcmp(x[i],"Stop")!=0); - is there anyway to compare x[i] to all the possible forms of "stop" (Stop, STOP, sTop, etc)?
Last edited on
You could convert x[i] to lowercase by using std::tolower on each character and then compare it to lowercase "stop".
Just make it all lower or uppercase then compare it to all lower or uppercase. You can do it manually with if statements and loops, you can use tolower/upper with a loop, or you can use std::transform and tolower/upper. There are probably other solutions out there too.

I would just do something like: std::transform(x.begin(), x.end(), x.begin(), tolower); or with c-strings something like std::transform(x, x + size, x, tolower); though this method may not work with unicode haven't tested but I know it works with ascii.
alternatively you can use [_stricmp] which does exactly the same as outlined above.
Note that _stricmp is a non-standard function.
Topic archived. No new replies allowed.