Bug #12035
closedscanf suspicious results.
Description
The code: 'a b c'.scanf('%[a] %[b] %[c]')
yields the result: ["a"] and not ["a","b","c"] as expected.
So far it seems that when sets of characters are used, only
the first one in the parse specification string actually returns
any data.
Updated by musgravejw (John Musgrave) almost 9 years ago
Peter Camilleri wrote:
The code: 'a b c'.scanf('%[a] %[b] %[c]')
yields the result: ["a"] and not ["a","b","c"] as expected.
So far it seems that when sets of characters are used, only
the first one in the parse specification string actually returns
any data.
I think you want: "a b c".scanf("%s %s %s")
Updated by PeterCamilleri (Peter Camilleri) almost 9 years ago
I think you're missing the point. Of course %s would seem to work in this case.
My question is about the %[set] (and %[^set]) format specifier that is documented as part of scanf.
It also works, but only once. That's the rub.
Updated by musgravejw (John Musgrave) almost 9 years ago
Peter Camilleri wrote:
I think you're missing the point. Of course %s would seem to work in this case.
My question is about the %[set] (and %[^set]) format specifier that is documented as part of scanf.
It also works, but only once. That's the rub.
Well, the sets in your string are whitespace delimited, so there is a mismatch between your input string and the format. You would need to match on the whitespace character.
"de f g".scanf("%[de]%s%[f]%s%[g]")
=> ["de", "f", "g"]
Updated by PeterCamilleri (Peter Camilleri) almost 9 years ago
That is what is so perplexing. The format I used was '%[a] %[b] %[c]'
Please note the explicit spaces between the formant elements. The docs
for scanf state that "White space in the format string matches any
amount of white space"
Updated by nobu (Nobuyoshi Nakada) almost 9 years ago
- Status changed from Open to Rejected
From http://ruby-doc.org/stdlib-2.2.4/libdoc/scanf/rdoc/Scanf.html#module-Scanf-label-Conversions
Matches a nonempty sequence of characters from the specified set of accepted characters. The usual skip of leading white space is suppressed.