Extracting 2 Far right characters
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
Hi,
How could I extract the 2 far right characters from cell string?
tt= {'United Kingdom TR';'United Kingdom SR';'United Kingdom WR';'Worldwide TC'};
Below is very inefficient.
splitStr = regexp( tt, ' ','split');
for runi= 1: length( tt)
    ttxt = splitStr{runi};
    peril(runi) = string( ttxt(end));
end 
peril = 
  1×4 string array
    "TR"    "SR"    "WR"    "TC"
댓글 수: 0
답변 (2개)
  Les Beckham
      
 2022년 5월 6일
        One approach that generates a cell array:
tt= {'United Kingdom TR';'United Kingdom SR';'United Kingdom WR';'Worldwide TC'};
c = cellfun(@(s)s(end-1:end), tt, 'UniformOutput', false)
If you prefer, you can convert this result to a string array like this
string(c)
댓글 수: 0
  Stephen23
      
      
 2022년 5월 6일
        tt = {'United Kingdom TR';'United Kingdom SR';'United Kingdom WR';'Worldwide TC'};
pe = regexp(tt,'\w\w$','match','once')
댓글 수: 0
참고 항목
카테고리
				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!


