Main Content

strip

Remove leading and trailing characters from string

Description

example

newStr = strip(str) removes all consecutive whitespace characters from the beginning and end of str, and returns the result as newStr.

example

newStr = strip(str,side) removes all consecutive white space characters from the side specified by side. The side argument can be 'left', 'right', or 'both'.

Note

Only Stateflow® charts that use MATLAB® as the action language support the strip operator.

Examples

expand all

Delete the leading and trailing space characters in a string.

h = "    Hello, world!      "
x = strip(h)

Stateflow chart that uses the strip operator in a state.

Results from stateflow chart that uses the strip operator in a state.

Delete the leading and trailing space characters from the left and right sides of a string.

h = "   Hello, world!      "
x = strip(h, 'left')
x2 = strip(h, 'right')

Stateflow chart that uses the strip operator in a state.

Results from stateflow chart that uses the strip operator in a state.

Limitations

Introduced in R2021b