本文整理自网络,侵删。
function DecStr(Input: string): string;vari, j, t: integer;s: string;beginif pos('-', Input) <> 0 thenbegin 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;endelseresult := Input;if s <> '' thenresult := result + s;end;
procedure TForm1.Button2Click(Sender: TObject);beginmemo1.Lines.Add(DecStr('1-10'));end;
原始: 1,3,5-10,15
结果: 1,3,5,6,7,8,9,10,15
相关阅读 >>
Delphi tstringdynarray 使用,分割字符串
Delphi idhttp解决获取utf-8网页中文乱码问题
Delphi 如何将access的ole对象字段存储的bmp图象显示出来
Delphi getprocessisadmin()判断exe是否以管理员身份启动
Delphi的tservice 服务路径获取 dll中获取文件路径
Delphi xe6 取得app自己的版本号(横跨4个平台)
更多相关阅读请进入《Delphi》频道 >>