TextUtility.SplitLines Method

Namespace
Kampute.DocToolkit.Support
Assembly
  • Kampute.DocToolkit.dll

Definition

Enumerates lines of text, splitting the input string into lines based on a specified maximum line width.
public static IEnumerable<string> SplitLines(string text, int maxLineWidth, bool preserveLineBreaks = false)

Parameters

text string
The text to split into lines.
maxLineWidth int
The maximum width of each line.
preserveLineBreaks bool optional
Indicates whether to preserve existing line breaks in the text.

Returns

IEnumerable<string>
An enumerable of strings, each representing a line of text.

Exceptions

ArgumentOutOfRangeException
Thrown when maxLineWidth is less than or equal to zero.

Remarks

This method splits the input text into lines based on the specified maximum line width. If preserveLineBreaks is set to true, it will respect existing line breaks in the text. Otherwise, it will treat the entire text as a single block and wrap it according to the specified width.
The method preserves leading and trailing whitespace in the lines. This behavior is intentional to maintain the original formatting of the text. If this behavior is not desired, consider trimming of each line after splitting.

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action.