From 2bb91e093cb57c5ba5ca71f0d0a63913a07f21f4 Mon Sep 17 00:00:00 2001 From: Lehner Florian Date: Tue, 2 Oct 2018 16:43:56 +0000 Subject: [PATCH] fmt: add example Sscanf Updates golang/go#27554. Change-Id: I2bf3d57ebeeb5dd50beffbc643a4ad10287b2c1e GitHub-Last-Rev: 4ffae55b4b2ca9d9b2a5b2b6dcef14ce43d83544 GitHub-Pull-Request: golang/go#27954 Reviewed-on: https://go-review.googlesource.com/c/138837 Reviewed-by: Rob Pike Run-TryBot: Rob Pike TryBot-Result: Gobot Gobot --- src/fmt/example_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index ecf3391ce7c..c2851759769 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -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")