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


本文整理自网络,侵删。

  

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('不是英文'); //返回 “是英文”

相关阅读 >>

Delphi中关于canvas.textout的用法

Delphi中的copy,delete,pos和leftstr,rightstr的用法

Delphi使用正则匹配网页数据

Delphi indy防止假死

Delphi编写的一款锁屏小工具

Delphi 删除目录下指定类型文件

Delphi xe webbroker 开发,解决 response 返回中文乱码问题

Delphi incyear、incmonth、incweek、incday、inchour、incminute、incsecond、incmillisecond �c 增时

Delphi 通过程序窗体句柄获取程序路径

Delphi从路径中分离文件名

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...