0

现在我有这个代码,但它总是设置为空

UNICODE_STRING str;
char *cmp = "Hello";

RtlInitUnicodeString (&str, L"Hello world!");

if( ( strstr((char * )str.Buffer, cmp) ) != NULL)
{
   // cmp founded in str.
}
else
{
   // cmp not founded in str. Always here, but why??
}

你能解释一下为什么我的 strstr 总是为空吗?

4

1 回答 1

0

您正在 Unicode 中搜索多字节字符串。使用wcsstr

wchar * cmp = L"Hello";
wcsstr(str.Buffer, cmp);

您通过转换为 来隐藏这一点char *


你真的应该为你的第二个请求问另一个问题,但你可能会写一个这样的函数:

void make_string_lower(WCHAR * str)
{
  while(str[0] != '\0') {
    if(iswalpha(str[0] && !iswlower(str[0]))) {
      str[0] = towlower(str[0]);
    }

    str++;
  }
}

或者使用_wcslwr.

于 2012-03-11T15:29:36.303 回答