Skip to main content

Text.lines

lineskeep_endings

Group: Text
Aliases: get lines

Documentation

Splits the text into lines, based on '\n', '\r' or '\r\n' line endings. Empty lines are added for leading newlines. Multiple consecutive newlines will also yield additional empty lines. A line ending at the end of the line is not required, but if it is present it will not cause an empty line to be added at the end.

Examples

Split the text 'a\nb\nc' into lines.

     'a\nb\nc'.lines == ['a', 'b', 'c']

Split the text '\na\n\nb\n\n' into lines.

     '\na\n\nb\n\n\n'.lines == ['', 'a', '', 'b', '', '']

Split the text '\na\nb\n' into lines, keeping the line endings.

     '\na\nb\n'.lines keep_endings=True == ['\n', 'a\n', 'b\n']