C++支持两种字符串,即常规的ANSI编码("字符串")和Unicode编码(L"字符串"),相应的就有两套字符串处理函数,比如:strlen和wcslen,分别用于处理两种字符串。 微软将这两套字符集及其操作进行了统一,通过条件编译(_UNICODE&_MBCS)来控制实际使用的字符集。
当没有定义_UNICODE & _MBCS宏时TCHAR = char,_tcslen = strlen,_tcsstr = strstr,_tcsncmp = strncmp当定义了_MBCS宏时TCHAR = char,_tcslen = strlen,tcsstr = mbsstr,_tcsncmp = _mbsnbcmp当定义了_UNICODE宏时,TCHAR = wchar_t , _tcslen = wcslen,_tcsstr = wcsstr,_tcsncmp = wcsncmp
字符串查找
TCHAR *szBuffer=_T("Good morning to you and to you !");
TCHAR *szFind=_T("you");
TCHAR *pFind = _tcsstr(szBuffer, szFind);
字符串反向查找
TCHAR *szBuffer=_T("Good morning to you and to you !");
TCHAR *szFind=_T("you");
TCHAR *pLast = szBuffer + _tcslen(szBuffer);
TCHAR *pFind;
for (; pLast >= szBuffer; pLast--)
{
if (*pLast == *szFind)
{
if (_tcsncmp(pLast, szFind, _tcslen(szFind)) == 0)
{
pLast = pLast;
}
}
}
参考资料
Generic-Text Mappings in Tchar.hstrlen, wcslen, _mbslen, _mbslen_l, _mbstrlen, _mbstrlen_lstrstr, wcsstr, _mbsstr, _mbsstr_lstrncmp, wcsncmp, _mbsncmp, _mbsncmp_l
转载于:https://www.cnblogs.com/lkpp/p/tchar_reverse_search.html
相关资源:JAVA上百实例源码以及开源项目