C++ , winapi Compare two WCHAR * strings
Asked Answered
P

4

5

I want to compare two WCHAR* strings.

How to do it?

P.S. I would like to ignore case while comparing.

I know you can use strcmpi but it id not working for WCHAR*.

Pteridophyte answered 30/8, 2011 at 15:9 Comment(0)
S
18

For case sensitive comparison, look at wcscmp

For case insensitive comparison, look at _wcsicmp

Skyjack answered 30/8, 2011 at 15:11 Comment(2)
How to use it so that I can ignore case?Pteridophyte
@SoumyajitRoy I'm sure something exists, but this question was tagged winapi.Skyjack
J
2

You have to use the WCHAR_t versions of strcmp. You can find the definitions here.

For case insensitive comparison use wcscasecmp.

Jelle answered 30/8, 2011 at 15:13 Comment(0)
G
2

Have you considered using StrCmpLogicalW()? Depending on your need that might be preferable to wcscmp.

Gallantry answered 30/8, 2011 at 15:15 Comment(3)
Again, this is case sensitive.Pteridophyte
No, it's not, take a look at the MSDN page. :-)Gallantry
However, StrCmpLogicalW would care for prefix numbers in string.Aspiration
V
0

There is lstrcmpi function in Win32 API which works with LPCTSTR instead of const char *. Don't know why it is not popular - I use it since 1994 (mostly lstrcmp without "i").

Victimize answered 26/5, 2017 at 11:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.