Effacer les filtres
Effacer les filtres

how to reverse a string using a FOR loop

5 vues (au cours des 30 derniers jours)
Kathrin Chari
Kathrin Chari le 14 Déc 2019
Modifié(e) : Ridwan Alam le 14 Déc 2019
How to reverse a string without using functions like fliplr,flip etc.

Réponse acceptée

Ridwan Alam
Ridwan Alam le 14 Déc 2019
Modifié(e) : Ridwan Alam le 14 Déc 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"

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by