I am checking whether a CString variable contains only] Chinese characters. The Unicode range for Chinese characters is 4E00 - 9FFF.
I am doing as follows:
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;
But if I do
if(ch=='\u4E00')
and input the symbol of \u4E00 then it works fine.
So my question is, how to find weather a character lies between a particular Unicode range?
One more thing: if I use if(ch=='\u4e00')
then it gives true, but if I do if(ch<='\u4e00')
it returns false. I don't understand this behavior!
My code is
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;
}
WCHAR
(defined by the Windows headers), orwchar_t
to use the C++ type. – Cody GrayL'\u4e00'
– Hans Passant