Reputation: 4118
I have method that find occurrences of string in other string. My question is how to make it to do no difference between small and capital letter?
int occurrences = 0;
string::size_type start = 0;
while ((start = base_string.find(to_find_occurrences_of, start)) != string::npos) {
++occurrences;
start += to_find_occurrences_of.length();
}
Upvotes: 0
Views: 2106
Reputation: 81
Check this answer - using std::search with a custom predicate seams the best way for me
https://stackoverflow.com/a/3152296/6910287
Upvotes: 2
Reputation: 41
Normalize both strings to upper or lowercase before comparison.
An explanation of how to do this using the standard library's tolower() or toupper() functions with the transform() function is given here: https://stackoverflow.com/a/313990/2355444
Upvotes: 2
Reputation: 1
Try using the tolower()
or toupper()
functions from <cctype> (ctype.h)
libraries on both sides of the comparison so that any difference becomes negligible.
Upvotes: 0
Reputation: 2176
Why not just set both strings to uppercase before you do the search?
Upvotes: 3