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

4 vues (au cours des 30 derniers jours)
Ervin DeBoy
Ervin DeBoy le 19 Oct 2020
Commenté : Ameer Hamza le 19 Oct 2020
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)

Réponse acceptée

Ameer Hamza
Ameer Hamza le 19 Oct 2020
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 commentaires
Ervin DeBoy
Ervin DeBoy le 19 Oct 2020
Thank you for helping me :)
Ameer Hamza
Ameer Hamza le 19 Oct 2020
I am glad to be of help! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by