Azzera filtri
Azzera filtri

how to reverse a string using a FOR loop

5 visualizzazioni (ultimi 30 giorni)
How to reverse a string without using functions like fliplr,flip etc.

Risposta accettata

Ridwan Alam
Ridwan Alam il 14 Dic 2019
Modificato: Ridwan Alam il 14 Dic 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"

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by