Thema: Delphi Wordwrap umbruch

Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
 
Delphi 10.4 Sydney
 
#7

AW: Wordwrap umbruch

  Alt 20. Nov 2018, 11:35
Delphi-Quellcode:
program WrapTextProject;

{$APPTYPE CONSOLE}

{$R *.res}


uses
  System.SysUtils,
  System.StrUtils;

const
  cText = 'The rain in Spain falls mainly on the plain.';

var
  MyWrapedText, MyWrapedWithEllipsisText: string;
  I, SplitPoints: Integer;

begin
  try
    Writeln('Org: ' + sLineBreak, cText, sLineBreak);

    MyWrapedText := WrapText(cText, sLineBreak, [' '], 15);
    Writeln('Wraped: ' + sLineBreak, MyWrapedText, sLineBreak);

    MyWrapedWithEllipsisText := '';
    SplitPoints := 0;
    for I := 1 to Length(MyWrapedText) do
    begin
      if IsDelimiter(sLineBreak, MyWrapedText, I) then
      begin
        Inc(SplitPoints);

        if SplitPoints > 2 then
        begin
          MyWrapedWithEllipsisText := MyWrapedText;
          SetLength(MyWrapedWithEllipsisText, I + 1);
          MyWrapedWithEllipsisText := MyWrapedWithEllipsisText + '...';
          Break;
        end;

      end;
    end;

    Writeln('Wraped with Ellipsis: ' + sLineBreak, MyWrapedWithEllipsisText, sLineBreak);

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

end.
Ausgabe:

Code:
Org:
The rain in Spain falls mainly on the plain.

Wraped:
The rain in
Spain falls
mainly on the
plain.

Wraped with Ellipsis:
The rain in
Spain falls
...
  Mit Zitat antworten Zitat