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 tstringdynarray 使用,分割字符串

Delphi xe10 对 json的解析应用

Delphi 开启内存泄漏报告模式

Delphi 检查用户输入必须是汉字串

Delphi 关闭显示器

Delphi idhttp解决获取utf-8网页中文乱码问题

Delphi 如何将access的ole对象字段存储的bmp图象显示出来

Delphi getprocessisadmin()判断exe是否以管理员身份启动

Delphi的tservice 服务路径获取 dll中获取文件路径

Delphi xe6 取得app自己的版本号(横跨4个平台)

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



打赏

取消

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

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

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

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

评论

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