检查是否字符串包含其它C [英] Check if string contains another C

查看:154
本文介绍了检查是否字符串包含其它C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有这个code,但它总是设置为空值

Now i have this code, but it always set null

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我的情况总是空?

Can you explain me why strstr in my case always null?

推荐答案

您正在搜索的统一code一个多字节字符串。使用 wcsstr

You're searching for a multi-byte string in a Unicode one. Use wcsstr:

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

您被强制转换为的char *

您真的应该问另外一个问题你的第二个要求,但你可能会写这样的功能:

You should really ask another question for your second request, but you might write a function like this:

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

    str++;
  }
}

或者使用 _wcslwr

这篇关于检查是否字符串包含其它C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆