昨天看了大家给我的分离字符串算法,但还是存在一个问题,程序并没有比较相等的时候,如果StrA=StrB,将在while陷入死循环,如果加入if StrA=StrB then... 将马上跳出,因为它只比较了主版本号就认为是相等而不理会下面的。procedure TForm1.Button1Click(Sender: TObject);
var
stra,strb:string;
nowa,nowb:integer;
begin
StrA:='2.0.2.33';
StrB:='2.0.2.1';
try
while true do
begin
if Pos('.',StrA)<>0 then
begin
NowA:=strtoint(copy(StrA,1,Pos('.',StrA)-1));
NowB:=strtoint(copy(StrB,1,Pos('.',StrB)-1));
end
else
begin
NowA:=strtoint(stra);
NowB:=strtoint(StrB);
end;
if NowA>NowB then
begin
ShowMessage('A大');
break;
end;
if NowA<NowB then
begin
ShowMessage('b大');
break;
end;
StrA:=copy(StrA,Pos('.',StrA)+1,Length(StrA)-Pos('.',StrA));
StrB:=copy(StrB,Pos('.',StrB)+1,Length(StrB)-Pos('.',StrB));
end;
except
on exception do ;
end;
end;
var
stra,strb:string;
nowa,nowb:integer;
begin
StrA:='2.0.2.33';
StrB:='2.0.2.1';
try
while true do
begin
if Pos('.',StrA)<>0 then
begin
NowA:=strtoint(copy(StrA,1,Pos('.',StrA)-1));
NowB:=strtoint(copy(StrB,1,Pos('.',StrB)-1));
end
else
begin
NowA:=strtoint(stra);
NowB:=strtoint(StrB);
end;
if NowA>NowB then
begin
ShowMessage('A大');
break;
end;
if NowA<NowB then
begin
ShowMessage('b大');
break;
end;
StrA:=copy(StrA,Pos('.',StrA)+1,Length(StrA)-Pos('.',StrA));
StrB:=copy(StrB,Pos('.',StrB)+1,Length(StrB)-Pos('.',StrB));
end;
except
on exception do ;
end;
end;
解决方案 »
- 如何判断一个字符类型的字段里的字符只是数字?
- delphi中怎么把一个整形数据转换成地址,赋值给一个数组作为首地址
- 在Pascal中有将字符类型转化为字符串类型的函数和方法吗?请高手帮忙!谢了!
- 如何看编译好得DELPHI程序界面上用了什么VCL控件
- 菜鸟软件上华军,竟然一下子成为华军图象捕捉类下载量排名第一。
- 我只设置时间,不设置日期,用什么控件好???怎么使用???
- 求文件分割和合并的代码
- 急 在线等待
- 没分也要问问题,不过有个好东东要大家死点脑细胞,嘿嘿。
- 我是新手,请教各位一个问题
- 运行时提示:[Fatal Error] Project1.dpr(1): File not found: 'System.pas' ??
- 怎么传递一个指针给函数??
var
stra,strb:string;
nowa,nowb:integer;
flag: boolean;
begin
StrA:='2.0.2.33';
StrB:='2.0.2.1';
flag := false;
try
while true do
begin
if Pos('.',StrA)<>0 then
begin
NowA:=strtoint(copy(StrA,1,Pos('.',StrA)-1));
NowB:=strtoint(copy(StrB,1,Pos('.',StrB)-1));
end
else
begin
NowA:=strtoint(stra);
NowB:=strtoint(StrB);
flag := true;
end;
if NowA>NowB then
begin
ShowMessage('A大');
break;
end;
if NowA<NowB then
begin
ShowMessage('b大');
break;
end;
if (NowA = NowB) and flag then
begin
ShowMessage('相等');
break;
end;
StrA:=copy(StrA,Pos('.',StrA)+1,Length(StrA)-Pos('.',StrA));
StrB:=copy(StrB,Pos('.',StrB)+1,Length(StrB)-Pos('.',StrB));
end;
except
on exception do ;
end;
end;
StrB := '2.4.5.6.7'而只要StrA和StrB的结构相同,不论是否完全相等,均没有问题程序在Delphi6中执行通过
StrA:='2.0.2.33';
StrB:='2.0.2.33';
弹出对话框提示相等
很奇怪你们为什么用while true do循环,而不用while Pos('.', StrA) <> 0 do原来程序结构很不合理,我只是懒得从头写