Why isn't strtrim working on my string?
조회 수: 21 (최근 30일)
이전 댓글 표시
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
2017년 7월 31일
What does this mean: 'I used ['|' a '|'] '?
strtrim(a)
works fine for me applied to the string you post.
채택된 답변
the cyclist
2017년 7월 31일
편집: the cyclist
2017년 7월 31일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!