现在有个 字符串是24位的数字和字母组合 想要进行大小比较。因为开头和结尾不确定,所以没法进行固定比较。想进行整个计算比较,但是20位就超出范围了,没法计算。请问怎么办呢,高手指点;
例如字符串 A00123456789012ADDEFWSER 与   A00123456789012ADDEFWSE9 进行比较~~ 

解决方案 »

  1.   


    var sl: tstringlist;
    begin
      sl:= tstringlist.Create;
      sl.Add('A00123456789012ADDEFWSER');
      sl.Add('A00123456789012ADDEFWSE9');
      sl.Sort;
      showmessage(sl.Strings[0]);
      sl.Free;
    end;
      

  2.   

    sl.Add('B00123456789012ADDEFWSER');'A00123456789012ADDEFWSE9' 始终是这个
      

  3.   

    字符串可以比较啊,长度不等没关系啊
      if edit1.Text=edit2.Text then
        showmessage('1=2')
      else if edit1.Text>edit2.Text then
        showmessage('1>2')
      else
        showmessage('1<2');
      

  4.   

    关键是里面字母也要进行比较例如 B>A 
      

  5.   

    自己写了个函数来比较 看来可行 不知道有没有数值运算的方法,那样会不会更快呢?
    //字符串比大小较函数
    //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;
      

  6.   

    sl.Strings[0] 是第一个.你改成 for i:= 0 to sl.count-1 do showmessage(sl.strings[i]);这个就是排序后的