RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.WrapText Function

Splits a string into multiple lines as its length approaches a specified size.

Pascal
function WrapText(const Line: string; const BreakStr: string; const BreakChars: TSysCharSet; MaxCol: Integer): string; overload;
function WrapText(const Line: string; MaxCol: Integer = 45): string; overload;
C++
AnsiString WrapText(const AnsiString Line, const AnsiString BreakStr, const TSysCharSet BreakChars, int MaxCol);
AnsiString WrapText(const AnsiString Line, int MaxCol = 45);

WrapText scans a string for occurrences of any of the characters specified by nBreakChars and inserts a line-break, specified by BreakStr, at the last occurrence of a character in nBreakChars before MaxCol. Line is the text WrapText scans. MaxCol is the maximum line length. 

If the BreakStr and nBreakChars parameters are omitted, WrapText searches for space, hyphen, or tab characters on which to break the line and inserts a carriage return/line feed pair (Windows) or a linefeed (Linux) at the break points. 

WrapText does not insert a break into an embedded quoted string (both single quotes and double quotes are supported). 

For example, the following call wraps the text into two lines at the last space character: 

WrapText('The rain in Spain falls mainly on the plain.', #13#10, ['.',' ',#9,'-'], 42); 

TSysCharSet bchars 

bchars << '.' << '-' << ' '; 

WrapText("The rain in Spain falls mainly on the plain.", "\r\n", bchars, 42); 

The result: 

The rain in Spain falls mainly on the 

plain. 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!