sscanf missing first zero
5 views (last 30 days)
Hello I need to pull out the number below from the string
and then convert it back to a string (so I want to strip any text)
So this is what I want '020550023'
But it misses the 1st zero.
Any suggestions to also get the first zero if its present?
Jan on 23 Apr 2021
No, sscanf considers the leading zeros. But numbers are stored in double format in Matlab (and other programming languages as well), which does not consider leading zeros. They are useful for mathematical operations.
If you want to keep the leading zero, you treat the information as a string. Then use corresponding string methods for the manipulation:
val = '020550023 MBB'
s = strtok(s, ' ');
index = find(~isstrprop(val, 'digit'), 1) - 1;
s = val(1:index);