我正在检查 CString 变量是否仅包含] 中文字符。汉字的 Unicode 范围是 4E00 - 9FFF。
我这样做如下:
CString str;
char ch;
GetDlgItemText( IDC_EDIT1, str );
for(int i=0;i<str.GetLength();i++) {
ch=str[i];
if(ch>='\u4E00'&&ch<='\u9FFF') {
//even if input chinese character here 'if' evaluates to false
SetDlgItemText( IDC_RICHEDIT21, str );
SendDlgItemMessage( IDC_RICHEDIT21, EM_REPLACESEL, TRUE, (LPARAM)(LPCTSTR)str);
} else
break;
但如果我这样做
if(ch=='\u4E00')
并输入 \u4E00 的符号然后它工作正常。
所以我的问题是,如何找到一个字符位于特定 Unicode 范围之间的天气?
还有一件事:如果我使用if(ch=='\u4e00')
then 它给出 true,但如果我这样做if(ch<='\u4e00')
它返回 false。我不明白这种行为!
我的代码是
CString str;
wchar_t ch;
GetDlgItemText( IDC_EDIT1, str );
for(int i=0;i<str.GetLength();i++) {
ch=str[i];
if(ch<='\u4e01') {
//returns false, but returns true if(ch=='\u4e01')
SetDlgItemText( IDC_RICHEDIT21, str );
SendDlgItemMessage( IDC_RICHEDIT21, EM_REPLACESEL, TRUE, (LPARAM)(LPCTSTR)str);
else
break;
}