秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
直接上代码:
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;

 

posted on 2024-06-05 06:28  秋·风  阅读(282)  评论(4)    收藏  举报