Split string into string based on character type

12 ビュー (過去 30 日間)
Marcin Dabrowski
Marcin Dabrowski 2019 年 7 月 9 日
編集済み: Stephen23 2019 年 7 月 9 日
Hello,
I have variable data that looks like this: 1A2 and is formatted number+letter(s)+number. I'd like to split this string to mentioned 3 types. Both numbers can be 2-digits. How can I do this?
I tried strtok and split but with no success. Thank you.

採用された回答

Stephen23
Stephen23 2019 年 7 月 9 日
編集済み: Stephen23 2019 年 7 月 9 日
>> S = '1A2';
>> C = regexp(S,'(\d+)(\D+)(\d+)','tokens','once')
C =
'1' 'A' '2'

その他の回答 (1 件)

Marcin Dabrowski
Marcin Dabrowski 2019 年 7 月 9 日
I think I found solution. I'm only missing how to extract first number.
string="1AA12";
check=isletter(string);
letter=string(check);
number2=strtok(string,letter);

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by