Adam Adam - 1 year ago 87
C++ Question

Case insensitive string comparison in C++

What is the best way of doing case insensitive string comparison in C++ with out transforming a string to all upper or lower case?

Also, what ever methods you present, are they Unicode friendly? Are they portable?

Rob Rob
Answer Source

Boost includes a handy algorithm for this:

#include <boost/algorithm/string.hpp>
// Or, for fewer header dependencies:
//#include <boost/algorithm/string/predicate.hpp>

std::string str1 = "hello, world!";
std::string str2 = "HELLO, WORLD!";

if (boost::iequals(str1, str2))
    // Strings are identical
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download