随笔 - 2146  文章 - 19 评论 - 11846 阅读 - 1267万


procedure SplitCommaCross(aList: TStrings);
  procedure SPlitCross(aList: TStrings);
  var
    LList: TStrings;
    a,b: Integer;
    i: Integer;
  begin
    if Pos('-', aList.Text) < 2 then Exit;
    LList := TStringList.Create;
    ExtractStrings(['-'], [' '], PChar(aList.Text), LList);
    if LList.Count = 2 then
    begin
      aList.Clear;
      a := StrToIntDef(LList[0], 0);
      b := StrToIntDef(LList[1], -1);
      for i := a to b do aList.Add(IntToStr(i));
    end;
    LList.Free;
  end;
var
  LList,RList: TStrings;
  s: string;
begin
  aList.CommaText := Trim(aList.Text);
  LList := TStringList.Create;
  RList := TStringList.Create;
  for s in aList do
  begin
    LList.Text := Trim(s);
    SPlitCross(LList);
    RList.AddStrings(LList);
  end;
  aList.Assign(RList);
  LList.Free;
  RList.Free;
end;

//测试
var
  str: string;
  List: TStrings;
begin
  str := '1-3,5-6,8';
  List := TStringList.Create;
  List.Text := Trim(str);
  SplitCommaCross(List);
  ShowMessage(List.Text); //1 2 3 5 6 8
  List.Free;
end;

posted on   万一  阅读(1695)  评论(1编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
历史上的今天:
2008-06-28 再学 GDI+[68]: 路径画刷(8) - SetBlendTriangularShaped、SetBlendBellShape
2008-06-28 再学 GDI+[67]: 路径画刷(7) - 画个五角星
2008-06-28 再学 GDI+[66]: 路径画刷(6) - SetInterpolationColors、GetRectangle
2008-06-28 再学 GDI+[65]: 路径画刷(5) - SetGammaCorrection
2008-06-28 再学 GDI+[64]: 路径画刷(4) - 还是 SetCenterColor、SetSurroundColors


点击右上角即可分享
微信分享提示