Функция для разворачивания строк

Материал из DRKB

Функция для разворачивания строк[править | править код]

{ **** UBPFD *********** by delphibase.endimus.com ****
>> Функция для "разворачивания" строк


Входные параметры:
Input - входная строка, которую необходимо представить в "развернутом виде"

на входе: 1,3,5-10,15
на выходе: 1,3,5,6,7,8,9,10,15 


Зависимости: стандартный набор включаемых модулей
Автор:       Ru, DiVo_Ru@rambler.ru, Одесса
Copyright:   DiVo 2002, creator Ru
Дата:        12 ноября 2002 г.
***************************************************** }

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;


Source: http://delphibase.endimus.com
ID: 00893