I am sure this would have been asked before but couldn't find it. Is there any built in (i.e. either using std::wstring's methods or the algorithms) way to case insensitive comparison the two wstring objects?
If you don't mind being tied to Microsoft implementation you can use this function defined in <string.h>
int _wcsnicmp( const wchar_t *string1, const wchar_t *string2, size_t count );
But if you want best performance/compatibility/functionality ratio you will probably have to look at boost library (part of it is stl anyway). Simple example (taken from different answer to different question):
#include <boost/algorithm/string.hpp> std::wstring wstr1 = L"hello, world!"; std::wstring wstr2 = L"HELLO, WORLD!"; if (boost::iequals(wstr1, wstr2)) { // Strings are identical }
Using the standard library:
bool comparei(wstring stringA , wstring stringB) { transform(stringA.begin(), stringA.end(), stringA.begin(), toupper); transform(stringB.begin(), stringB.end(), stringB.begin(), toupper); return (stringA == stringB); } wstring stringA = "foo"; wstring stringB = "FOO"; if(comparei(stringA , stringB)) { // strings match }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With