获取打印页号列表

获取打印页号列表
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 2011-06-28 11:18  万一  阅读(1589)  评论(1)  编辑  收藏
上一篇:双轴快速排序


下一篇:2021-05-13 随想随记