delphi 判断字符串是否包含汉字


本文整理自网络,侵删。

 
procedure TForm1.Button1Click(Sender: TObject);
var
  str : string;
  pStr : PWideChar;
  isHZ : Boolean;
  i , s, m : Integer;
  byteArr : TBytes;
begin
  str := Trim('23432432223432423');
  pStr := PWideChar( str );
  byteArr := WideBytesOf(str);

   while pStr^ <> #0 do
    begin
        //  汉字
      case pStr^ of
        Char($4E00) .. Char($9FA5) :
        begin
           isHZ := True;
           Break;
        end ;
        // 全角中文符号
        Char($FF00) .. Char($FFEF) :
        begin
           isHZ := True;
           Break;
        end ;
        // 半角中文符号
        Char($3000) .. Char($303F) :
        begin
           isHZ := True;
           Break;
        end ;
        else
        //  EditChar.Text :=       EditChar.Text + pStr^;
      end;

      Inc( pStr );
    end;
    //
    if isHZ then
      Vcl.Dialogs.MessageDlg('包含汉字',mtInformation,[mbOK],0)
    else
      Vcl.Dialogs.MessageDlg('没有包含汉字!',mtInformation,[mbOK],0);

end;

相关阅读 >>

Delphi 设置richedit的行间距

Delphi idhttp用法详解

Delphi正则表达式

Delphi ioutils 获取当前目录下所有的文件/文件夹

Delphi guid单元

Delphi手动创建dataset并插入值

Delphi sysutils.stringreplace - 替换

Delphi 已经最小化的窗体如何让它自己还原?

Delphi 删除文件的函数

Delphi windows 编程[2] - 学习窗体生成的过程二

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...