Print Last Letter in a String
63 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Star Strider
2015 年 1 月 31 日
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 件のコメント
Image Analyst
2015 年 1 月 31 日
Another way to get it printed out to the command window:
fprintf('%c\n', S1(end));
Oscar Sotomayor
2021 年 7 月 31 日
Check documentation for function extractBetween
3 件のコメント
Oscar Sotomayor
2021 年 8 月 2 日
編集済み: Rik
2021 年 8 月 2 日
If x has the text. The next code extract the two lat letters
newStr = extractBetween(x,strlength(x)-1,strlength(x))
Rik
2021 年 8 月 2 日
The question was about only the last letter, so you need a minor edit:
x="%@3Gb6kl@3G9@33G";
newStr = extractBetween(x,strlength(x),strlength(x))
x=char(x);
newStr = extractBetween(x,strlength(x),strlength(x))
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!