aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLehner Florian <dev@der-flo.net>2018-10-02 16:43:56 +0000
committerRob Pike <r@golang.org>2018-10-06 19:18:34 +0000
commit2bb91e093cb57c5ba5ca71f0d0a63913a07f21f4 (patch)
tree1836086990da078d9553e6657d809434e47205ac /src
parent46cf91a75fc0a516eb76b66b1a61202f3546bd7e (diff)
downloadgo-2bb91e093cb57c5ba5ca71f0d0a63913a07f21f4.tar.xz
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 <r@golang.org> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/fmt/example_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go
index ecf3391ce7..c285175976 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")