字符串可以比较啊,长度不等没关系啊 if edit1.Text=edit2.Text then showmessage('1=2') else if edit1.Text>edit2.Text then showmessage('1>2') else showmessage('1<2');
关键是里面字母也要进行比较例如 B>A
自己写了个函数来比较 看来可行 不知道有没有数值运算的方法,那样会不会更快呢? //字符串比大小较函数 //s1 标杆 //s2 比较对象 //返回值 0 相等 1 标杆小于比较对象 2 标杆大于比较对象function ComParString(s1, s2: string): integer; var i, s: integer; begin if S1 = S2 then Result := 0; if length(s1) > length(s2) then Result := 2; if length(s1) < length(s2) then Result := 1; if length(s1) = length(s2) then begin for I := 0 to length(s1) do begin if StrToIntDef(IntToStr(DigitToInt(s1[i], 36) + 1), 0) > StrToIntDef(IntToStr(DigitToInt(s2[i], 36) + 1), 0) then begin Result := 2; end; if StrToIntDef(IntToStr(DigitToInt(s1[i], 36) + 1), 0) < StrToIntDef(IntToStr(DigitToInt(s2[i], 36) + 1), 0) then begin Result := 1; end; end; end; end;
sl.Strings[0] 是第一个.你改成 for i:= 0 to sl.count-1 do showmessage(sl.strings[i]);这个就是排序后的
var sl: tstringlist;
begin
sl:= tstringlist.Create;
sl.Add('A00123456789012ADDEFWSER');
sl.Add('A00123456789012ADDEFWSE9');
sl.Sort;
showmessage(sl.Strings[0]);
sl.Free;
end;
if edit1.Text=edit2.Text then
showmessage('1=2')
else if edit1.Text>edit2.Text then
showmessage('1>2')
else
showmessage('1<2');
//字符串比大小较函数
//s1 标杆
//s2 比较对象
//返回值 0 相等 1 标杆小于比较对象 2 标杆大于比较对象function ComParString(s1, s2: string): integer;
var
i, s: integer;
begin
if S1 = S2 then
Result := 0;
if length(s1) > length(s2) then
Result := 2;
if length(s1) < length(s2) then
Result := 1;
if length(s1) = length(s2) then
begin
for I := 0 to length(s1) do
begin
if StrToIntDef(IntToStr(DigitToInt(s1[i], 36) + 1), 0) > StrToIntDef(IntToStr(DigitToInt(s2[i], 36) + 1), 0) then
begin
Result := 2;
end;
if StrToIntDef(IntToStr(DigitToInt(s1[i], 36) + 1), 0) < StrToIntDef(IntToStr(DigitToInt(s2[i], 36) + 1), 0) then
begin
Result := 1;
end; end;
end;
end;