Filter löschen
Filter löschen

Why isn't strtrim working on my string?

16 Ansichten (letzte 30 Tage)
JFz am 31 Jul. 2017
Kommentiert: JFz am 31 Jul. 2017
I have a simple string, that has many leading spaces: a = ' abcd' I want to remove the white space by using strtrim, but it is not working. I used ['|' a '|'] and then newchr = strtrim(a) but the newchr still has the leading spaces. Why?
The string a is read from excel file which I tried to remove the spaces but also failed.
  1 Kommentar
Adam am 31 Jul. 2017
What does this mean: 'I used ['|' a '|'] '?
works fine for me applied to the string you post.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 31 Jul. 2017
Bearbeitet: the cyclist am 31 Jul. 2017
Your whitespace might be "significant", as mentioned in the documentation for strtrim.
For example, if you do
s = [char(160) 'abcd']
then the strtrim command will have no effect.
What do you get for these whitespace characters if you type
where s is your string?
You could use regexprep to get rid of significant whitespace:
s = regexprep(s,char(160),'')
You'll need to take care of not removing those special characters from other places.

Weitere Antworten (0)


Mehr zu Characters and Strings finden Sie in Help Center und File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by