?
=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=
Is there some quick C++ way I can do something similar to string::find ,
but case insensitive ?
but case insensitive ?
Nils O. Selåsdal said:Is there some quick C++ way I can do something similar to string::find ,
but case insensitive ?
Change to string::const_iterator, it seems to work fine.John said:You can use the predicate version of std::search
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::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 ( );
}
Untested code.
John said:You can use the predicate version of std::search
bool ci_equal(char ch1, char ch2)
{
return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
}
Fortunatly for me, I need only care about ascii a-z,A-Z ......
1-char-to-1-char conversion is not possible. Wide character support
doesn't alleviate this at all :-(((
Standardised whole-string case conversion functions would be deerly
needed, even if it's left to the implementation or the application to
implement them for a particular locale.
Nils O. Selåsdal said:Is there some quick C++ way I can do something similar to string::find ,
but case insensitive ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.