Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does MATLAB have a strip function for strings?

Tags:

string

matlab

Is there a simple function f such that

f(' hello, world! ' ) == 'hello, world!'

I can strip out the spaces (or any character for that matter) using regexes, but this seems like applying a hammer to the problem. I'd just like to know if there is something simple which I've missed.

like image 289
Derek Avatar asked Dec 10 '22 21:12

Derek


2 Answers

No need to use a hammer, simply use strtrim.

From the documentation:

S = strtrim(str) returns a copy of string str with all leading and trailing white-space characters removed. A white-space character is one for which the isspace function returns logical 1 (true).

like image 163
Stewie Griffin Avatar answered Dec 20 '22 15:12

Stewie Griffin


To remove the spaces on the side of the string, use the strtrim command.

like image 41
Peut22 Avatar answered Dec 20 '22 17:12

Peut22