如何使用 sscanf 忽略字段(%* 被拒绝)

我希望在使用 sscanf 处理字符串时忽略特定字段。


sscanf 的手册页说


An optional '*' assignment-suppression character: scanf() reads input as directed by the conversion specification, but discards the input.  No corresponding pointer argument is required, and this specification is not included in the count of successful assignments returned by scanf().


尝试在 Golang 中使用它,忽略第三个字段:


if c, err := fmt.Sscanf(str, " %s %d %*d %d ", &iface.Name, &iface.BTx, &iface.BytesRx); err != nil || c != 3 {

编译正常,但在运行时 err 设置为:


bad verb %* for integer


Golang doco 没有特别提到 %* 转换规范,但它确实说,


Package fmt implements formatted I/O with functions analogous to C's printf and scanf.


这并不表示 %* 没有实现,所以......我做错了吗?或者它只是被悄悄地省略了?...但是,它为什么要编译?


神不在的星期二
浏览 383回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go