Показать сообщение отдельно
  #7  
Старый 01.11.2010, 16:42
Аватар для NumLock
NumLock NumLock вне форума
Let Me Show You
 
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
По умолчанию

Код:
function GetWords(AStr: String): TStringList;
var
  i: Integer;
begin
  Result:=TStringList.Create;
  i:=Pos(' ', AStr);
  while i>0 do
  begin
    Result.Add(Copy(AStr, 1, i-1));
    Delete(AStr, 1, i);
    i:=Pos(' ', AStr);
  end;
  if Length(AStr)>0 then Result.Add(AStr);
end;

procedure Formated(FLines: TStrings; FFormatedLines: TStrings; Width: Integer);
var
  i: Integer;
  aWords: TStringList;
  aLine: String;
  aWidth: Integer;
begin
  FFormatedLines.Clear;
  for i:=0 to FLines.Count-1 do
  begin
    aWords:=GetWords(FLines[i]);
    aLine:='';
    if aWords.Count>0 then
    begin
      while aWords.Count>0 do
      begin
        aWidth:=Length(aLine+aWords[0]+' ');
        if (aWidth>Width) and (aLine<>'') then
        begin
          FFormatedLines.Add(aLine);
          aLine:='';
        end;
        if Length(aLine)>0 then aLine:=aLine+' ';
        aLine:=aLine+aWords[0];
        aWords.Delete(0);
      end;
      if aLine<>'' then FFormatedLines.Add(aLine);
      aWords.Free;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo2.Lines.LoadFromFile('c:\Downloads\memo');
  Memo2.Lines.Insert(0, '123456789_123456789_123456789_123456789_123456789_123456789_');
  Memo2.Text:=StringReplace(Memo2.Text, #9, '*', [rfReplaceAll, rfIgnoreCase]);
  Formated(Memo2.Lines, Memo1.Lines, 60);
  Memo1.Lines.SaveToFile('c:\Downloads\memo3');
end;
__________________
Пишу программы за еду.
__________________
Ответить с цитированием