问题
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??
}
Can you explain me why strstr in my case always null?
回答1:
You're searching for a multi-byte string in a Unicode one. Use wcsstr
:
wchar * cmp = L"Hello";
wcsstr(str.Buffer, cmp);
You were hiding this by casting to 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++;
}
}
Alternatively use _wcslwr
.
来源:https://stackoverflow.com/questions/9656245/check-if-string-contains-another-c