本文介绍了C ++中不区分大小写的字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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?
,它们是Unicode友好的吗?
Also, what ever methods you present, are they Unicode friendly? Are they portable?
推荐答案
Boost包含一个方便的算法:
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
}
这篇关于C ++中不区分大小写的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!