Delphi判断字符串是否是数字、字母、大小写字母

本文介绍了一种使用Pascal语言实现的字符串类型判断方法,包括数字、大写字母、小写字母及英文字符的判断,并提供了具体的函数实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

function IsNumberic(Vaule:String):Boolean;   //判断Vaule是不是数字
var
i:integer;
begin
result:=true;   //设置返回值为 是(真)
Vaule:=trim(Vaule); //去空格
for i:=1 to length(Vaule) do //准备循环
    begin
      if not Vaule[i] in ['0'..'9'] then //如果Vaule的第i个字不是0-9中的任一个
        begin
          result:=false; //返回值 不是(假)
          exit; //退出函数
        end;
    end;
end;

function IsUpperCase(Vaule:String):Boolean;   //判断Vaule 是不是大写字母
var
i:integer;
begin
result:=true; //设置返回值为 是
Vaule:=trim(Vaule);   //去空格
for i:=1 to length(Vaule) do   //准备循环
    begin
      if not Vaule[i] in ['A'..'Z'] then //如果Vaule的第i个字不是A-Z中的任一个
        begin
          result:=false; //返回值 不是
          exit; //退出函数
        end;
    end;
end;

function IsLowerCase(Vaule:String):Boolean; //判断Vaule 是不是小写字母
var
i:integer;
begin
result:=true;   //设置返回值为 是
Vaule:=trim(Vaule);   //去空格
for i:=1 to length(Vaule) do //准备循环
    begin
      if not Vaule[i] in ['a'..'z'] then   //如果Vaule的第i个字不是a-z中的任一个
        begin
          result:=false;   //返回值 不是
          exit;   //退出函数
        end;
    end;
end;

同理 如果想判断是不是字母的话

function IsEnCase(Vaule:String):boolean;    //判断Vaule 是不是字母
var
i:integer;
begin
result:=true;   //设置返回值为 是
Vaule:=trim(Vaule); //去空格
for i:=1 to length(Vaule) do //准备循环
    begin
      if (not Vaule[i] in ['A'..'Z']) or
         (not Vaule[i] in ['a'..'z']) then   //如果Vaule的第i个字不是A-Z或者a-z中的任一个
        begin
          result:=false;   //返回值 不是
          exit;   //退出函数
        end;
    end;
end;

下面是调用方法:
if IsNumberic('嘿嘿') then showmessage('是数字') else showmessage('我不是数字'); //返回 “我不是数字”
if IsUpperCase('HAHA') then showmessage('是大写字母') else showmessage('不大写字母'); //返回 “是大写字母”
if IsLowerCase('abcdEfg') then showmessage('是小写字母') else showmessage('不是小写字母'); //返回 “不是小写字母”
if IsEnCase('abcdEfg') then showmessage('是英文 ') else showmessage('不是英文'); //返回 “是英文”
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值