Extracting 2 Far right characters
2 ビュー (過去 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 で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!