原文链接:http://blog.csdn.net/sptoor/article/details/4930069
思路:汉字匹配,把字符都转换成宽字符,然后再匹配。
- 需要用到以下和宽字符有关的类:
1、wstring:
作为STL中和string相对应的类,专门用于处理宽字符串。方法和string都一样,区别是value_type是wchar_t。wstring类的对象要赋值或连接的常量字符串必须以L开头标示为宽字符。
2、wregex:
和regex相对应,专门处理宽字符的正则表达式类。同样可以使用regex_match()和regex_replace()等函数。regex_match()的结果需要放在wsmatch类的对象中。
- 字符和宽字符的相互转换:
1、RTL的方法
//把字符串转换成宽字符串 setlocale( LC_CTYPE, "" ); // 很重要,没有这一句,转换会失败。 int iWLen= mbstowcs( NULL, sToMatch.c_str(), sToMatch.length() ); // 计算转换后宽字符串的长度。(不包含字符串结束符) wchar_t *lpwsz= new wchar_t[iWLen+1]; int i= mbstowcs( lpwsz, sToMatch.c_str(), sToMatch.length() ); // 转换。(转换后的字符串有结束符) wstring wsToMatch(lpwsz); delete []lpwsz; //把宽字符串转换成字符串,输出使用 int iLen= wcstombs( NULL, wsm[1].str().c_str(), 0 ); // 计算转换后字符串的长度。(不包含字符串结束符) char *lpsz= new char[iLen+1]; int i= wcstombs( lpsz, wsm[1].str().c_str(), iLen ); // 转换。(没有结束符) lpsz[iLen] = '