如何不区分大小写比较两个字符串?

shiningstar 2002-04-09 08:51:55
rt.
3x.
...全文
293 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shiningstar 2002-04-09
  • 打赏
  • 举报
回复
感谢,我是Delphi新手,刚从C++转过来的。有些东西还不太熟悉,希望大侠们多多指点。
chechy 2002-04-09
  • 打赏
  • 举报
回复
StrIComp
uses SysUtils;
procedure TForm1.Button1Click(Sender: TObject);

var
Msg: string;
CompResult: Integer;
begin
Msg := Edit1.Text;
CompResult := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text));
if CompResult < 0 then
Msg := Msg + ' is less than '
else if CompResult > 0 then
Msg := Msg + ' is greater than '
else
Msg := Msg + ' is equal to '
Msg := Msg + Edit2.Text;
ShowMessage(Msg);
end;
dancemaple 2002-04-09
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
s1, s2: string;
begin
s1 := 'adfad';
s2 := 'ASDFA';
if (UpperCase(s1) > UpperCase(s2)) then
ShowMessage('>')
else
ShowMessage('<=');
end;
不怕输 2002-04-09
  • 打赏
  • 举报
回复
我的方法是,将两个字符串都变成大写或小写,然后再比较。(使用的函数为LowerCase,UpperCase)
cooling 2002-04-09
  • 打赏
  • 举报
回复
你先把他们转化成都是大写的或都是小写的,再比较不就可以了啊。

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧