1. 程式人生 > >delphi 判斷字符串有中文

delphi 判斷字符串有中文

位置 break class for AR 退出 字符 nbsp ger

function TForm1.IsHaveChinese(judgeStr: string; var posInt: integer): boolean;
var
  p: PWideChar; // 要判斷的字符
  count: integer; // 包含漢字位置
  isHave: boolean; // 是否包含漢字返回值
begin

  isHave := false; // 是否包含漢字返回值默認為false
  count := 1; // 包含漢字位置默認為1

  p := PWideChar(judgeStr); // 把要判斷字符串轉換

// 循環判斷每個字符
  while p^ <> #0
do begin case p^ of #$4E00..#$9FA5: begin isHave := true; // 設置是否包含漢字返回值為true posInt := count; // 設置包含漢字位置 break; // 退出循環 end; end; Inc(p); Inc(count); // 包含漢字位置遞增 end; result := isHave; end;

delphi 判斷字符串有中文