extracting number from a string
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!