![]() |
Re: String zerlegen ab einer bestimten länge aber auf...
habe rausgefunden woran es liegt!
Da es der einzige Text it der probleme macht am C'T Das ' reicht um die Funktion auszuhebeln... Hmpf danke Euch |
Re: String zerlegen ab einer bestimten länge aber auf...
Hallo Sebastian,
mit dem single quote bist du das Opfer einer Schlamperei der VCL Macher geworden. Die Jungs haben eine Sonderbehandlung der beiden ASCII QuoteChars in der Funktion fest verdrahtet. Sorry, aber das wusste ich auch nicht. Ich greife mal den Ansatz von alzaimar auf und lege eine Funktion WrapText() mit kompatibler Signatur vor:
Delphi-Quellcode:
Wenn ich deinen Beispieltext in ein Memo lade, dann erhalte ich ein akzeptables Ergebnis so:
function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet;
MaxCol: Integer): string; var s: TStrings; iFirst, iLast: Integer; begin s := TStringList.Create; try iFirst := 1; while iFirst < Length(Line) do begin iLast := Min(Pred(iFirst + MaxCol), Length(Line)); while (iLast > iFirst) and (iLast < Length(Line)) and not (Line[iLast] in BreakChars) do Dec(iLast); s.Add(BreakStr + Copy(Line, iFirst, Succ(iLast - iFirst))); iFirst := Succ(iLast); end; Result := s.Text; finally s.Free; end; end;
Delphi-Quellcode:
Freundliche Grüße
procedure TDemoForm.ButtonClick(Sender: TObject);
var s: TStrings; i: Integer; begin s := TStringList.Create; with Memo do begin for i := 0 to Pred(Lines.Count) do s.Text := s.Text + WrapText(Trim(Lines[i]), '> ', [' ', #9], 50); Lines.Text := s.Text; end; s.Free; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:26 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz