码迷,mamicode.com
首页 > Windows程序 > 详细

delphi 判断字符串有中文

时间:2018-06-16 14:32:06      阅读:508      评论:0      收藏:0      [点我收藏+]

标签:function   result   als   int   sha   bre   ges   nbsp   lse   

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 判断字符串有中文

标签:function   result   als   int   sha   bre   ges   nbsp   lse   

原文地址:https://www.cnblogs.com/yangxuming/p/9190339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!