1
0
mirror of https://github.com/golang/go synced 2024-11-17 13:04:54 -07:00

fmt: add example Sscanf

Updates golang/go#27554.

Change-Id: I2bf3d57ebeeb5dd50beffbc643a4ad10287b2c1e
GitHub-Last-Rev: 4ffae55b4b
GitHub-Pull-Request: golang/go#27954
Reviewed-on: https://go-review.googlesource.com/c/138837
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Lehner Florian 2018-10-02 16:43:56 +00:00 committed by Rob Pike
parent 46cf91a75f
commit 2bb91e093c

View File

@ -63,6 +63,19 @@ func ExampleFscanln() {
// 3: ken, 271828, 3.141590 // 3: ken, 271828, 3.141590
} }
func ExampleSscanf() {
var name string
var age int
n, err := fmt.Sscanf("Kim is 22 years old", "%s is %d years old", &name, &age)
if err != nil {
panic(err)
}
fmt.Printf("%d: %s, %d\n", n, name, age)
// Output:
// 2: Kim, 22
}
func ExamplePrint() { func ExamplePrint() {
const name, age = "Kim", 22 const name, age = "Kim", 22
fmt.Print(name, " is ", age, " years old.\n") fmt.Print(name, " is ", age, " years old.\n")