Separating numbers and characters from input

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일

0 개 추천

str = '123wd57ab934bd3';
z = regexp(str,'(\d*)([a-z]*)','tokens');
out = [z{:}];
out = out(~cellfun(@isempty,out));

댓글 수: 3

If you want them separately
numbers = regexp(str,'(\d+)','match');
chars = regexp(str,'([a-z]+)','match');
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.
str = '123wd57ab934bd3';
z = str2double(regexp(str,'\d*','match'));

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2016년 10월 25일

댓글:

2016년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by