|
doe john wrote:
> HI, I have a chain of characters string + number delimited by semi '; ' as following
> line ='name.rrr; ; 78;7;6;;string;;0'
> first I replacethe ';' by a tab
> line = regexprep(line,';','\t')
> Then, I try to use
> [A, count, errmsg, nextindex]=sscanf(line, '%s, %d,%d,%d,%d,%s,%s,%s,%d')
> but I was not able to retrieve those different data. I get the name.rr in A but in error ,
> I get matching failure in format. I don't understand why it doesnt retrieve other data.
When you put a comma in your sscanf format, then sscanf will look for a literal comma in
your input. Do not put any delimiter between the various format elements. A lot of people
put spaces, but it is best not to even put those. For example, you might use
'%s%d%d%d%d%s%s%s%d'
However, you are still going to have problems with the empty fields. Both of the
format elements you have specified, %s and %d, skip -all- leading whitespace, where
"whitespace" is tab or space (or vertical tab, or carriage return, or newline.)
The leading %s format will read the 'name.rrr', but the %d after that will skip over
to the 78, the second %d will get the 7, the third %d will get the 6, then the
fourth %d will skip over and try reading from 'string', which is going to fail.
And if it did somehow work (e.g., the string happened to be all digits), then
the %s that follows in the format string would skip over the whitespace to the 0
leaving you with a %s and %d not satisfied.
I would suggest that for your purposes, it would probably be easier to split
at the semi-colon and parse the individual parts.
|