필터 지우기
필터 지우기

last letter in a string

조회 수: 180 (최근 30일)
Max
Max 2015년 11월 11일
댓글: Walter Roberson 2023년 10월 25일
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