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 

相关阅读 >>

Delphi中的instrrev函数(倒找文本)

Delphi opendialog使用方法

Delphi 动态调用chm文件

Delphi debug权限提升

Delphi winapi: flashwindow - 闪烁窗口

Delphi dateof、timeof、yearof、monthof、weekof、dayof、hourof、minuteof、secondof、millisecondof �c 提取时间成分

Delphi 主线程等待子线程的安全退出

Delphi xe10 android安卓 移动端 messagedlg 用法

Delphi ntfs usn 磁盘文件搜索

Delphi monthcalendar1 获取选中日期

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...