Filter löschen
Filter löschen

how to reverse a string using a FOR loop

5 Ansichten (letzte 30 Tage)
Kathrin Chari
Kathrin Chari am 14 Dez. 2019
Bearbeitet: Ridwan Alam am 14 Dez. 2019
How to reverse a string without using functions like fliplr,flip etc.

Akzeptierte Antwort

Ridwan Alam
Ridwan Alam am 14 Dez. 2019
Bearbeitet: Ridwan Alam am 14 Dez. 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"

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by