Hi all,

I want to locate a substring within a C++ string where the case does 
not matter. I did a bunch of Google-ing and found the code below. The 
code compiles fine, but I get an error when trying to call it.

This works (standard find()):  pos = dateStr.find("Mon");

This gets an error (ci_find()): pos = dateStr.ci_find("Mon");

The error I get is: 'struct std::string' has no member named 'ci_find'

How do I make this a member function, or how else can I do a 
case-insensitive find?

~Rick

----------------------------
CODE
----------------------------
// predicate version of std::search for case-insensitive searches
bool ci_equal(char ch1, char ch2)
{
return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
}


size_t ci_find(const string& str1, const string& str2)
{
     string::const_iterator pos = search(str1.begin(), str1.end(), 
str2.begin(), str2.end(), ci_equal);
     if (pos == str1.end())
         return string::npos;
     else
         return pos - str1.begin();
}

Reply via email to