Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Extension method: IEnumerable<string> WordWrap(this string, int, int)

Declaration

public static IEnumerable<string> WordWrap(
    this string text,
    int maxWidth,
    int hangingIndent = 0
)

Summary

Word-wraps the current string to a specified width. Supports UNIX-style newlines and indented paragraphs.

Parameters

this stringtext Text to be word-wrapped.
intmaxWidth The maximum number of characters permitted on a single line, not counting the end-of-line terminator.
inthangingIndent The number of spaces to add to each line except the first of each paragraph, thus creating a hanging indentation.

Remarks

The supplied text will be split into "paragraphs" at the newline characters. Every paragraph will begin on a new line in the word-wrapped output, indented by the same number of spaces as in the input. All subsequent lines belonging to that paragraph will also be indented by the same amount.

All multiple contiguous spaces will be replaced with a single space (except for the indentation).