I have variable WCHAR sDisplayName[1024];
How can I check if sDisplayName contains the string “example”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This does not cover the case where the string in
sDisplayNamestarts with “example” or has “example” in the middle. For those cases, you can usewcsncmpandwcsstr.Also this check is case sensitive.
Also this will break if
sDisplayNamecontains garbage – i. e. is not null terminated.Consider using std::wstring instead. That’s the C++ way.
EDIT: if you want to match the beginning of the string:
If you want to find the string in the middle
Note that wcsstr returns nonzero if the string is found, unlike the rest.