本文整理自网络,侵删。
//判断字符是否是汉字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 adoquery连接数据库的查询、插入、删除、修改
Delphi tdirectory.getdirectories获取子目录及文件
更多相关阅读请进入《Delphi》频道 >>