how to reverse a string using a FOR loop
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kathrin Chari
el 14 de Dic. de 2019
Editada: Ridwan Alam
el 14 de Dic. de 2019
How to reverse a string without using functions like fliplr,flip etc.
0 comentarios
Respuesta aceptada
Ridwan Alam
el 14 de Dic. de 2019
Editada: Ridwan Alam
el 14 de Dic. de 2019
Update:
myString = "abcdefg";
myChar = char(myString);
% using array indexing
myNewStr = string(myChar(end:-1:1));
% using FOR loop:
myNewChar = [];
for i = 1:length(myChar)
myNewChar = [myNewChar,myChar(end-i+1)];
end
myNewStr = string(myNewChar);
% myNewStr =
% "gfedcba"
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!