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

4 次查看(过去 30 天)
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)

更多回答(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