Print Last Letter in a String
82 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Im trying to print out the last Alphabetic letter in a string.
For example S1 = '%@3Gb6kl@3G9@33G';
I want the letter G to get printed out.
Any help would be great :)
0 Kommentare
Antworten (2)
Star Strider
am 31 Jan. 2015
Your ‘S1’ is a string array, so you can use the end function to get the last letter:
S1 = '%@3Gb6kl@3G9@33G';
LastLetter = S1(end)
produces:
LastLetter =
G
1 Kommentar
Image Analyst
am 31 Jan. 2015
Another way to get it printed out to the command window:
fprintf('%c\n', S1(end));
Oscar Sotomayor
am 31 Jul. 2021
Check documentation for function extractBetween
3 Kommentare
Oscar Sotomayor
am 2 Aug. 2021
Bearbeitet: Rik
am 2 Aug. 2021
If x has the text. The next code extract the two lat letters
newStr = extractBetween(x,strlength(x)-1,strlength(x))
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!