fmt.Scanf: any way to do something like %*f in C

464 views
Skip to first unread message

朱必胜

unread,
Jul 11, 2013, 9:14:31 PM7/11/13
to golan...@googlegroups.com
Hi,
I have read the scan.go in go/src, and can't find an easy way to skip a field in the input stream, in C, we have a %*f, with * to skip, how to do that for golang?

Rob Pike

unread,
Jul 12, 2013, 12:44:15 AM7/12/13
to 朱必胜, golan...@googlegroups.com
There is no way beyond storing into a variable whose value you ignore.

-rob

Carlos Castillo

unread,
Jul 12, 2013, 3:41:14 AM7/12/13
to golan...@googlegroups.com, 朱必胜
There are two ways to do this without creating a new variable: http://play.golang.org/p/RjPsgsCCfG

But honestly, it makes more sense to simply create the extra variable and ignore it, so that if you ever need the field, or reuse the code, you aren't confused later.

Also method 2 is more brittle to changes in the implementation of scanf.
Reply all
Reply to author
Forward
0 new messages