find case insensitive code example
Example 1: findstr case insensitive
Find strings with case-insensitive search using -i flag as follows:
findstr -i "Case_insensitive_substring"
For example:
dir | findstr -i "Case_insensitive_file_name"
Example 2: wstring find case insensitive
using namespace std;
inline bool caseInsCharCompSingle(char a, char b) {
return(toupper(a) == b);
}
string::const_iterator caseInsFind(string& s, const string& p) {
string tmp;
transform(p.begin(), p.end(), // Make the pattern
back_inserter(tmp), // upper-case
toupper);
return(search(s.begin(), s.end(), // Return the iter-
tmp.begin(), tmp.end(), // ator returned by
caseInsCharCompSingle)); // search
}
int main() {
string s = "row, row, row, your boat";
string p = "YOUR";
string::const_iterator it = caseInsFind(s, p);
if (it != s.end()) {
cout << "Found it!\n";
}
}