本文整理自网络,侵删。
//判断字符是否是汉字function IsMBCSChar(const ch: Char): Boolean; begin Result := (ByteType(ch, 1) <> mbSingleByte); end; 注:只能判断AnsiString类型的
参看StrUtils.ByteType函数
由于 Delphi2005 支持中文标识符,在编写 PASCAL 词法分析器的过程中遇到了这个问题,经过多次试验找到了解决方案,至今未发现问题。代码如下:
//判断字符是否是汉字 function IsHZ(ch: WideChar): boolean;var i:integer;begin i:=ord(ch); if( i<19968) or (i>40869) then result:=false else result:=true;end;
//判断字符是否是汉字 function TForm1.IsHZ(ch: Char): boolean;begin //返回值为 0 的时候为单字节字符,返回值为 1 的时候为多字节字符 if(ord(bytetype(ch,1))=1) then result:=true else result:=false;end;
//判断字符是否是汉字function IsMBCSChar(const ch: Char): Boolean; begin Result := (ByteType(ch, 1) <> mbSingleByte); end;
相关阅读 >>
Delphi 32位程序 out of memory 内存不足时解决办法之一
Delphi setwindowshookex - 设置钩子 unhookwindowshookex - 卸掉钩子
Delphi xe5实现datetimetounix/unixtodatetime的一点小改进
Delphi dbgrideh 的分组统计 datagrouping
更多相关阅读请进入《Delphi》频道 >>