Reverse a string using a FOR loop
4 次查看(过去 30 天)
显示 更早的评论
So I have this string array.
fair4 =
9×1 string array
"The"
"reyen"
"in"
"Speyen"
"steyes"
"meyenly"
"in"
"the"
"pleyen."
I want to write a for loop to reverse the order of the letter in words in fair4 without using the revrese function. So "The" would be "eht."
I have this code but I don't know how to fix it.
fair5c= fair4;
summer= char(fair4);
summer= string(summer(end:-1:1));
yellow= []
for i= 1:length(summer)
yellow= [yellow,summer(end-i+1)];
end
fair5c= string(yellow)
回答(1 个)
David Hill
2020-2-12
count=1;
for k=length(fair4):-1:1
fair5(count)=fair4(k);
count=count+1;
end
fair5=fair5';
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!