Separating numbers and characters from input

17 ビュー (過去 30 日間)
Valeria Chacon
Valeria Chacon 2016 年 10 月 25 日
コメント済み: Andrei Bobrov 2016 年 10 月 26 日
If a user inputs a random amount of characters For example: str=input(prompt,'s'); and they input: 123wd57ab934bd3 how can I separate the numbers and the characters? Thank you!

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2016 年 10 月 25 日
str = '123wd57ab934bd3';
z = regexp(str,'(\d*)([a-z]*)','tokens');
out = [z{:}];
out = out(~cellfun(@isempty,out));
  3 件のコメント
Valeria Chacon
Valeria Chacon 2016 年 10 月 25 日
is there any way that I could pull out the numbers? maybe even one by one? so instead of separating I get only the numbers.
Andrei Bobrov
Andrei Bobrov 2016 年 10 月 26 日
str = '123wd57ab934bd3';
z = str2double(regexp(str,'\d*','match'));

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by