直接上代码:
procedure TForm1.Button1Click(Sender: TObject); var s: string; function StringContainsChinese(const str: Widestring): boolean; var i: integer; begin for i := 1 to Length(str) do begin // 检查是否在基本汉字范围内 if (Ord(str[i]) >= $4E00) and (Ord(str[i]) <= $9FFF) then begin Result := true; Exit; // 找到一个就返回 true end; end; Result := false; // 没有找到中文字符 end; begin s:='12中文测试'; if StringcontainsChinese(s) then showmessage('字符串包含中文') else showmessage('字符串不包含中文'); end;


浙公网安备 33010602011771号