last letter in a string
205 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Max
am 11 Nov. 2015
Kommentiert: Walter Roberson
am 25 Okt. 2023
I have a string that is going to keep updating
Say x='ear' how do I take the last later in the string so say lastletter='r' is it possible to have this work generally to always take the last later in a the string so say x gets updated to 'eart' lastletter=-t'
0 Kommentare
Akzeptierte Antwort
Thorsten
am 11 Nov. 2015
x = 'ear';
lastletter = x(end);
3 Kommentare
Walter Roberson
am 25 Okt. 2023
No that would not work. When you use == to compare a character vector to a string scalar, the character vector gets converted to a string scalar and then the == would be comparing for string equality not character equality.
On the other hand
x(x == 'a')
would pull out all of letter 'a'
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos 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!