Main Content

strip

Remove leading and trailing characters from string

Since R2021b

Description

example

newStr = strip(str) removes consecutive whitespace characters from the beginning and end of the string str.

example

newStr = strip(str,side) removes consecutive white space characters from the side specified by side.

newStr = strip(___,stripCharacter) strips the character specified by stripCharacter. You can use any of the input arguments in the previous syntaxes.

Note

The strip operator is not supported in Stateflow® charts that use C as the action language.

Examples

expand all

Remove the leading and trailing spaces and return the string "Hello, world!" .

str = "    Hello, world!      ";
newStr = strip(str);

Stateflow chart that uses the strip operator in a state.

Remove the leading spaces and return the string "Hello, world!    ".

str = "    Hello, world!    ";
str1 = strip(h,"left");

Stateflow chart that uses the strip operator in a state.

Remove the trailing spaces and return the string "    Hello, world!".

str = "    Hello, world!    ";
str1 = strip(h,"right");

Stateflow chart that uses the strip operator in a state.

Remove the leading and trailing hyphens and return the string "Hello, world!" .

str = "----Hello, world!----";
newStr = strip(str);

Stateflow chart that uses the strip operator in a state.

Input Arguments

expand all

Input string, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Side of string to strip, specified as "left", "right", or "both".

Character to remove, specified as a string scalar.

Limitations

Version History

Introduced in R2021b