1)中文字符的unicode范围:U+4E00..U+9FA5
参考http://summerbell.javaeye.com/blog/563095
2)中文标点符号unicode范围:0xff01 ~ 0xff5e
3)中文字符的高字节小于0,英文字符的高字节等于0,该规则可以用来提取中文字符;
4)读取文件时,目前只知道一个一个字节读取文件,getline(inFile,string bufferLine),未发现有以宽字节的方式读取文件,故读取中文字符文件时,需要char2wchar_t转换函数, MultiByteToWideChar,WideCharToMultiByte
//将单字节char*转化为宽字节wchar_t*
wchar_t* AnsiToUnicode( const char* szStr)
{
int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 );
if (nLen == 0)
{
return NULL;
}
wchar_t* pResult = new wchar_t[nLen];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen );
return pResult;
}
//将宽字节wchar_t*转化为单字节char*
char* UnicodeToAnsi( const wchar_t* szStr )
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL );
return pResult;
}
5)linux版本中多字节char(ansik编码)转换成宽字节(unicode编码)使用:
setlocale(LC_ALL, "zh_CN");//依据系统而定,告诉系统接下来将ansik转换成zh_CN格式的unicode编码
//setlocale(LC_ALL, "chs"); vs2008中这样也ok
int n = mbstowcs(wc,word,sizeof(word));
setlocale(LC_ALL,"C");
6)打印中文字符:也可以用wprintf,具体注意问题http://blog.csdn.net/gonxi/archive/2010/10/10/5931006.aspx
wcout.imbue(locale("chs"));
wchar_t ss = L'你';
wcout<<ss;
setlocale(LC_CTYPE, "C");
printf("%S", L"unicode中文/n"); // ⑤
wprintf(L"%s", L"unicode中文/n"); // ⑦
7)字符,字节和编码知识 http://www.regexlab.com/zh/encoding.htm