splitlines
Splits text at line breaks.
Category: Language Fundamentals > Data Types
Syntax
C = splitlines(str)
Returns the lines of str as a column.
Description
The break may be a line feed, a carriage return, or the pair carriage return plus line feed, so text from any platform is split correctly. The line breaks themselves are not kept. A text with no break returns a single line.
Input arguments
str- String scalar or character vector.
Output arguments
C- String array (for a string input) or cell array (for a char input) with one line per element.
Example
splitlines("a" + newline + "b")
splitlines(sprintf('l1\nl2\r\nl3'))
Output
ans = 2×1 string array
"a"
"b"
ans = 3×1 cell
{'l1'}
{'l2'}
{'l3'}