昨天看了大家给我的分离字符串算法,但还是存在一个问题,程序并没有比较相等的时候,如果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;
解决方案 »
- 有没有好用的播放 flv 视频的 控件 或者其他方案
- DBGrid选择多行问题求助!散100分~~~~~
- 如何在DELPHI 的工程文件中来实现函数。
- 文件或目录转换成 TreeView时,添加图片的问题?
- 庆贺!!!!!!!!!!
- 如何获得一个汉字的笔划数?
- 存储过程问题!
- 如何使窗口打开就显示最大化
- 如何用delphi代码从winsocket服务器上下载文件?
- delphi7+indy10使用idftp连接ftp(TLS/SSL协议)的问题
- 运行时提示:[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原来程序结构很不合理,我只是懒得从头写