C++中不区分大小写的字符串比较 [英] Case-insensitive string comparison in C++
本文介绍了C++中不区分大小写的字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C++ 中进行不区分大小写的字符串比较而不将字符串转换为全部大写或全部小写的最佳方法是什么?
What is the best way of doing case-insensitive string comparison in C++ without transforming a string to all uppercase or all lowercase?
请说明这些方法是否对 Unicode 友好以及它们的可移植性如何.
Please indicate whether the methods are Unicode-friendly and how portable they are.
推荐答案
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++中不区分大小写的字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文