Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!news2!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe02.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: sscanf
References: <ge4gmp$r05$1@fred.mathworks.com>
In-Reply-To: <ge4gmp$r05$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 30
Message-ID: <%HkNk.818$o57.618@newsfe02.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe02.iad 1225119611 24.79.146.116 (Mon, 27 Oct 2008 15:00:11 UTC)
NNTP-Posting-Date: Mon, 27 Oct 2008 15:00:11 UTC
Date: Mon, 27 Oct 2008 10:00:28 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:497446


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.