WinAPI字符及字符串函数(13):lstrcmp、lstrcmpi
Lstrcmp区分大小写;Lstrcmpi不区分大小写。返回值:-1,0,1,其中0表示相同。
接口
使用
窗口、消息、系统工具、变量、类、图形、控件、窗体、
对话框、
type
t form 1 = class(t form)
button 1:t button;
button 2:t button;
button 3:t button;
button 4:t button;
button 5:t button;
过程按钮1Click(发件人:to object);
过程按钮2 click(Sender:to object);
过程按钮3 click(Sender:to object);
过程button 4 click(Sender:to object);
过程按钮5Click(发件人:to object);
end;var form 1:t form 1;
实现
{$R *。DFM }
const
Msgs:array[-1..1]of Char =(' a }
n:= lstrcmpi(P1,p2);
ShowMessageFmt('%s %s %s ',[p1,Msgs[n],p2]);{ A = A }
end;程序TForm1。Button3Click(发送方:to object);var
p1,p2:PChar;
n:整数;
begin
P1:= ' ABC ';
p2:= ' ABCD ';
n := lstrcmp(p1,p2);
ShowMessageFmt('%s %s %s ',[p1,Msgs[n],p2]);{ABC < abcd}
n := lstrcmpi(p1,p2);
ShowMessageFmt('%s %s %s ',[p1,Msgs[n],p2]);{ ABC < ABCD }
end;{这和Delphi的CompareStr和CompareText还是有很大区别}
procedure form 1 . button 4 click(sender:to object);var
p1,p2:PChar;
n:整数;
begin
P1:= ' A ';
p2:= ' a ';
n := CompareStr(p1,p2);
show message(IntToStr(n));{-32}
n := CompareText(p1,p2);
show message(IntToStr(n));{ 0 }
end;{也不同于StrComp,strcomp,strcomp和str comp }
proceduretform 1 . button 5 click(sender:to object);var
p1,p2:PChar;
n:整数;
begin
P1:= ' A ';
p2:= ' a ';//考试编者按
n := StrComp(p1,p2);
show message(IntToStr(n));{-32}
n := StrIComp(p1,p2);
show message(IntToStr(n));{0}
n := StrLComp(p1,p2,1);
show message(IntToStr(n));{-32 }
n:= str licom(P1,p2,1);
show message(IntToStr(n));{ 0 }
end;
结束。
0条评论