I have come across code snippets where developers search strings within a string using “OR” to encompass all combination of the search string.
This is not a good move.
for ex:
str.find(“abc”) || str.find(“Abc”)….
The good way of solving this would be to use:
transform and tolower.
1) First convert both the search string and main string into lower or upper chars.
2) then search for the string. In this way, your not entirely dependent on the case sensitivity.
std::string newString=””;
std::transform( cmd.begin(), cmd.end(), newString.begin(), tolower );
3) then you can do the searching.
Leave a Reply