|
|
发表于 2006-10-15 21:09:28
|
显示全部楼层
汉字在内存中占用两字节,(gbk/gb2312/gb18030这几种编码好像都是)
但汉字与英文字母在内存中最大的区别就是汉字占用两字节的首位都是1,而英文字母是0
之所以你可以用位运算可以查出是否为汉字
String str = "我的名字是linux先生,我的email是xxx@linuxsir.cn。";
for (int i = 0; i < str.length(); i++)
{
if (str & 0xff00)
{
//... cout << " the character is chinese";
i++;
}
else
{
//... cout << " the character is english";
}
} |
|