remove to only one whitespace in a string
이전 댓글 표시
hi all, I am writing a function that to remove the blanks between the words and return it to only one space. like
mystr = 'Lets go party'
Return to
remove_blanks(mystr) = 'Lets go party'
So far, I got mystr = 'Lets go party'; function remove_blanks(mystr) y = mystr(isspace(mystr))='';
I know how to remove all the space between the words but I don't know how to remove to one left.
채택된 답변
추가 답변 (1개)
Guillaume
2014년 11월 11일
0 개 추천
A regular expression is the simplest way to do that. Otherwise you can always strsplit the string (which ignores multiple spaces by default) and strjoin it back.
카테고리
도움말 센터 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!