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 winapi: getwindowtext - 获取窗口标题

Delphi 动态设置屏幕分辨率

Delphi 字符串反转函数

Delphi datasnap双缓存下载文件

Delphi 按字母排序的windows窗口公用消息

Delphi xe 移动平台 showmodal 范例

Delphi 窗体不可用

Delphi获取盘符代码

Delphi vcl 的 tpagecontrol 控件,实现对页签的拖动

Delphi 删除cookies文件

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



打赏

取消

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

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

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

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

评论

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