delphi 数字排序自动完成  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 数字排序自动完成


function DecStr(Input: string): string;
var
i, j, t: integer;
s: string;
begin
if pos('-', Input) <> 0 then
begin
   while length(Input) <> 0 do
   begin
     if Input[1] = ',' then
     begin
       i := strtoint(s);
       delete(Input, 1, 1);
       result := result + s + ',';
       s := '';
     end
     else
     begin
       if Input[1] = '-' then
       begin
         i := strtoint(s);
         delete(Input, 1, 1);
         t := pos(',', Input);
         result := result + s + ',';
         s := '';
         if t = 0 then
         begin
           j := strtoint(Input);
           Input := '';
         end
         else
         begin
           j := strtoint(copy(Input, 1, t - 1));
           delete(Input, 1, t);
         end;
         inc(i);
         while i < j + 1 do
         begin
           result := result + inttostr(i) + ',';
           inc(i);
         end;
       end
       else
       begin
         s := s + Input[1];
         delete(Input, 1, 1);
       end;
     end;
   end;
end
else
result := Input;
if s <> '' then
result := result + s;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Lines.Add(DecStr('1-10'));
end;

原始: 1,3,5-10,15

结果: 1,3,5,6,7,8,9,10,15 


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.040410041809082 seconds