last letter in a string
154 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Thorsten
2015 年 11 月 11 日
x = 'ear';
lastletter = x(end);
3 件のコメント
Walter Roberson
2023 年 10 月 25 日
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'
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!