比较wstring和忽略大小写 [英] Comparing wstring with ignoring the case
问题描述
我敢肯定这会在之前被问到,但找不到.是否有任何内置方式(即使用std :: wstring的方法或算法)对两个wstring对象进行不区分大小写的比较?
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?
推荐答案
如果您不介意与Microsoft实现绑定,则可以使用在< string.h>
中定义的此函数>
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
);
但是,如果您想要最佳的性能/兼容性/功能比,则可能需要查看boost库(无论如何它都是stl).简单示例(取自针对不同问题的不同答案):
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
}
这篇关于比较wstring和忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!