View source code
Display the source code in std/string.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.string.wrap
Wrap text into a paragraph.
S wrap(S)
(
S s,
in size_t columns = 80,
S firstindent = null,
S indent = null,
in size_t tabsize = 8
)
if (isSomeString!S);
The input text string s is formed into a paragraph by breaking it up into a sequence of lines, delineated by \n, such that the number of columns is not exceeded on each line. The last line is terminated with a \n.
Parameters
Name | Description |
---|---|
s | text string to be wrapped |
columns | maximum number of columns in the paragraph |
firstindent | string used to indent first line of the paragraph |
indent | string to use to indent following lines of the paragraph |
tabsize | column spacing of tabs in firstindent[] and indent[] |
Returns
resulting paragraph as an allocated string
Example
writeln(wrap("a short string", 7)); // "a short\nstring\n"
// wrap will not break inside of a word, but at the next space
writeln(wrap("a short string", 4)); // "a\nshort\nstring\n"
writeln(wrap("a short string", 7, "\t")); // "\ta\nshort\nstring\n"
writeln(wrap("a short string", 7, "\t", " ")); // "\ta\n short\n string\n"
Authors
Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.