1
0
mirror of https://github.com/golang/go synced 2024-09-29 17:24:34 -06:00

fmt: add example Sscanf

Updates golang/go#27376.
This commit is contained in:
Lehner Florian 2018-10-01 21:10:08 +02:00
parent 43cd907017
commit 4ffae55b4b

View File

@ -63,6 +63,19 @@ func ExampleFscanln() {
// 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() {
const name, age = "Kim", 22
fmt.Print(name, " is ", age, " years old.\n")