简体   繁体   中英

MFC : How to check if a character input is unicode?

I have an input text field which accepts a certain maximum number of characters. This number of characters should change though if the character inputs are unicode. Question:

Is there a way I could check if the character input is unicode or not?

Check the length of the string and size in bytes.

  • If both are equal then it ASCII.

  • If size in bytes is larger than length of the string, then it contains UNICODE characters.

I remember using Len() and LenB() functions in VS6 for the same...

GoodLUCK!!

Microsoft supplies the API IsTextUnicode. Some of its bugs are famous.

我想使用正则表达式检查每个字符输入是否为unicode更容易... :)

Any character you input is Unicode, because Unicode covers all code pages supported by Windows, and more.

You can call IsWindowUnicode and if the result is true, and you retrieve the text with GetWindowTextW (or GetWindowText and UNICODE is defined), then the result is stored in a Unicode string (wchar_t or WCHART, same thing).

Otherwise you retrieve the result in a char array and it is encoded in the system code page (also improperly called "ANSI code page")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM