extracting number from a string

조회 수: 13 (최근 30일)
amin mirzaei
amin mirzaei 2019년 8월 2일
댓글: amin mirzaei 2019년 8월 2일
How can I extract the number from the string with out regexp?
example: I am 19 and my brother is 14 years old
'19','12'
  댓글 수: 2
Rik
Rik 2019년 8월 2일
편집: Rik 2019년 8월 2일
Why don't you want to use regexp? Should the code support decimal values as well? Numbers in the form of 1E5? Also, is this homework?
amin mirzaei
amin mirzaei 2019년 8월 2일
it's part of homework

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

답변 (1개)

Rik
Rik 2019년 8월 2일
You can either use ismember to determine which positions contain the characters you're looking for, or you can use isstrprop. Then you can loop over the groups of digits. You can use find and diff to determine the positions where such a group starts. If you need to support decimal values as well things will get slightly more complicated.
I will not provide a complete working solution because this is homework. You can find guidelines for posting homework on this forum here.
You should also be aware that the string data type is something different from a char array.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by