How to remove spaces from a string using while if or for/

조회 수: 4 (최근 30일)
Ervin DeBoy
Ervin DeBoy 2020년 10월 19일
댓글: Ameer Hamza 2020년 10월 19일
Need to use for if or while , finding the length will probably help initiate the loop , but how to remove spaces its complicated
c = 'that is some tick stuf f f'
l = length(c)
for a = 0:l
if c == ' '
c==''
end;
disp(c)

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 19일
It is important that you traverse the string from the end toward the beginning.
c = 'that is some tick stuf f f';
l = numel(c);
for a = l:-1:1
if c(a) == ' '
c(a) = [];
end
end
disp(c)
  댓글 수: 2
Ervin DeBoy
Ervin DeBoy 2020년 10월 19일
Thank you for helping me :)
Ameer Hamza
Ameer Hamza 2020년 10월 19일
I am glad to be of help! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by