Problem using sscanf in picking out numbers from string.
Show older comments
So, I have the string:
str1=D993920x2ExlsSuited20.xls
And I want to pick out the numbers in the string, to give me a vector like
res=[993920 2 20]
Allowing me to pick up the last number for use in naming a txt document.
However, I cannot get sscanf to give me this.
I tried using.
res = sscanf(str1, ['%d'])
Shouldn't this give me the numbers in the string at least? All I get is a space sign...
All help on this would be greatly appreciated.
Best regards, Nicki Eriksen.
Accepted Answer
More Answers (1)
str1 = 'D993920x2ExlsSuited20.xls';
%method 1
res = str2double(regexp(str1, '\d+', 'match'))
%method 2
res = double(extract(string(str1), digitsPattern))
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!