如標題
读一个BYTE,
如果这个BYTE的内容<128,就是英文。如果>128,再读一个BYTE,合并起来为一个中文。
给你一个VC的代码:
作如下修改:
CString str = "好好学习good good study";
CString tmp = "";
int len = str.GetLength();
TCHAR chTmp =\0;
for(int i = 0 ; i < len;)
{
chTmp = str.GetAt(i);
if (chTmp < 0)
{//中文字符
tmp.Format("%c%c",str.GetAt(i),str.GetAt(i+1));
cout<<"中文字符: "<<tmp<<endl;
i+=2;
}
else{
cout<<"英文字符: "<<str.GetAt(i)<<endl;
i++;
}
}
AnsiString s = "我爱中国,I love china";
WideString ws;
ws=s;
AnsiString temps;
for (int i=1;i<=ws.Length();i++)
{
temps = WideString(ws[i]);
if(temps.Length()>=2)
ShowMessage("["+temps+"]中文");
else
ShowMessage("["+temps+"]英文");
}
URL= http://delphi.ktop.com.tw/topic.asp?TOPIC_ID=20191
可用WideString來判斷中文字
var s:string;
ws:widestring;
i:integer;
begin
ws:=s;
for i:=1 to length(ws) do
begin
if length(ws[i])>=2 then // 中文
else // 英文
;
end;
end;
~~~Delphi K.討論區站長~~~
强烈同意楼上两位的说法,判断是否是汉字,就是判断字符的ASCII(个人观点),但是有一个函数可以直接判断ASCII的取值范围就是:isascii
BCB的例子
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
int main(void)
{
char c = C;
if (isascii(c))
printf("%c is ascii\n",c);
else printf("%c is not ascii\n",c);
return 0;
}
AnsiString s="1234567890方法";
if(s.WideCharBufSize()==1+ (int)(s.Length()/2) )
ShowMessage("All Chinese!");
else
{
if( s.WideCharBufSize()==1+ s.Length() )
ShowMessage("All English!");
else
ShowMessage("Mix!");
}