Why isn't strtrim working on my string?

12 ビュー (過去 30 日間)
JFz
JFz 2017 年 7 月 31 日
コメント済み: JFz 2017 年 7 月 31 日
Hi,
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.
Thanks,
Jennifer
  1 件のコメント
Adam
Adam 2017 年 7 月 31 日
What does this mean: 'I used ['|' a '|'] '?
strtrim(a)
works fine for me applied to the string you post.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2017 年 7 月 31 日
編集済み: the cyclist 2017 年 7 月 31 日
Your whitespace might be "significant", as mentioned in the documentation for strtrim.
For example, if you do
s = [char(160) 'abcd']
strtrim(s)
then the strtrim command will have no effect.
What do you get for these whitespace characters if you type
double(s)
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.
  1 件のコメント
JFz
JFz 2017 年 7 月 31 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by