strip

Trims leading and trailing characters from strings.

Syntax

R = strip(s, mode)

R = strip(s, mode, trim)

Inputs

s
Input string(s) to be trimmed. If s is a cell, all elements should be of type string.
Type: string | cell
mode
Indicates whether leading and/or trailing characters should be trimmed from s. Valid values are 'both', 'left', 'right'.
Type: string
trim
Optional string specifying characters(s) to be trimmed. If trim is a cell, all elements should be of type string. Whitespace is the default if no string is specified.
Type: string | cell

Outputs

R
R will have the trimmed strings. If s is a cell, R will also be a cell.
Type: string | cell

Examples

Trims both leading and trailing characters from a string:
R = strip(',,,this is a test,,', 'both', ',')
R = this is a test
Trims leading characters from a cell array of strings:
R = strip({',,,this is a test****0123******????***','foo2*'}, 'right', {',', ' ', '?', '*', '0123'})
R =
  [1,1] ,,,this is a test
  [1,2] foo2
}