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

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 日

1 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

製品

質問済み:

2020 年 10 月 19 日

コメント済み:

2020 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by