Main Content

newline

Create newline character

Description

c = newline creates a newline character. newline is equivalent to char(10) or sprintf('\n'). Use newline to concatenate a newline character onto a character vector or a string, or to split text on newline characters.

Examples

collapse all

Create a newline character with newline and concatenate it onto a character vector.

chr = 'Whose woods these are I think I know.';
chr = [chr newline 'His house is in the village though']
chr = 
    'Whose woods these are I think I know.
     His house is in the village though'

Although chr displays on two lines, chr is a 1-by-73 character vector that contains the two sentences, separated by a newline.

Create a newline character. Then use + to concatenate the newline character and more text onto the end of a string.

str = "In Xanadu did Kubla Khan";
str = str + newline + "A stately pleasure-dome decree"
str = 
    "In Xanadu did Kubla Khan
     A stately pleasure-dome decree"

Although str displays on two lines, str is a 1-by-1 string.

Tips

  • The newline function does not return a carriage return character. A carriage return is equivalent to char(13) or sprintf('\r').

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2016b