strtrim

Trims leading and trailing whitespaces from strings, matrices and cell arrays. For matrices, leading and trailing whitespaces are stripped from each row to the size of the longest string in the matrix, to make the length of each row consistent.

Syntax

R = strtrim(s)

Inputs

s
Type: string | mat | cell

Outputs

R
Type: string | mat | cell

Examples

String input:
R = strtrim('    strtrim Example1   ')
R = strtrim Example1
Matrix input:
R = strtrim([' string1234   '; '  string12    '])
R =
string1234
string12
Cell array input:
R = strtrim({'123   ', '  example3     '})
R =
{
[1,1] 123
[1,2] example3
}