Delphi检测字符串中是否包含汉字

来源:互联网 发布:西安千度网络传销 编辑:程序博客网 时间:2024/05/22 05:24
procedure TMainForm.Button1Click( Sender : TObject );
var
  str : string;
  pStr : PWideChar;
  isHZ : Boolean;
  i , s, m : Integer;
  byteArr : TBytes;
begin
  str := Trim( EditStr.Text );
  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;
原创粉丝点击