last letter in a string

204 次查看(过去 30 天)
Max
Max 2015-11-11
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'

采纳的回答

Thorsten
Thorsten 2015-11-11
x = 'ear';
lastletter = x(end);
  3 个评论
Justin
Justin 2023-10-25
编辑:Justin 2023-10-25
AllA = x(x == "a")
I have not tested this, just a belief this works
Walter Roberson
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 CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by