I want to compare strings in Persian (utf8). I know I must use some thing like L”گل” and it must be saved in wchar_t * or wstring. the question is when I compare by the function compare() strings I dont get the right result.
Share
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.
If the strings that you want to compare are in a specific, definite encoding already, then don’t use
wchar_tand don’t useL""literals — those are not for Unicode, but for implementation-defined, opaque encodings only.If your strings are in UTF-8, use a string of
chars. If you want to convert them to raw Unicode codepoints (UCS-4/UTF-32), or if you already have them in that form, store them in a string ofuint32_ts, orchar32_ts if you have a modern compiler.If you have C++11, your literal can be
char str8[] = u8"گل";orchar32_t str32[] = U"گل";. See this topic for some more on this.If you want to interact with command line arguments or the environment, use
iconv()to convert from WCHAR to UTF-32 or UTF-8.