FUNCTION REFERENCE

readlines

Read lines of text file as a string array.

Read lines of text file as a string array.

Syntax

lines = readlines(filename); lines = readlines(filename, Name, Value)

Returns a column string array. A trailing line ending does not add an empty last line. Supports WhitespaceRule ('preserve', 'trim', 'trimleading', 'trimtrailing'), EmptyLineRule ('read', 'skip', 'error'), LineEnding (default ["\n","\r\n","\r"]), and Encoding ('UTF-8', 'US-ASCII', 'ISO-8859-1', 'system'). LineEnding interprets escape notation such as "\n" and "\r\n"; readlines with "\r\n" also accepts lone CR and LF.

Example

writelines(["a"; "b"], "lines.txt"); lines = readlines("lines.txt")   % ["a"; "b"]

Differences from MATLAB: A trailing line ending does not add an empty last line. Text is bounded to 256 KiB per file and 65536 strings; UTF-16/UTF-32 encodings are not supported yet.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.