string.find | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

string.find

ok so you know how you can use string. find to find a word in a sentence. how would i find the word regardless of its capitalization ex: string x = "hello" if (string::npos != x.find("hello")) cout << "string found" << endl; in this example how would i make it so that if string x = "HeLLo, it would still print out string found regardless of the capitalization differences

10th Aug 2018, 10:00 PM
Harry
Harry - avatar
2 Answers
+ 2
you can turn the string to lowercase before you check if you want by either using a for loop to go threw the string and tolower on each char or use transform with tolower.
10th Aug 2018, 10:15 PM
Mooaholic
Mooaholic - avatar
0
Mooaholic thanks dude that worked perfectly! although i used the ascii table values insteam of tolower. thanks man!
11th Aug 2018, 4:37 AM
Harry
Harry - avatar