Golang fmt.Sscanf() function example

package fmt

Sscanf scans the argument string, storing successive space-separated values into successive arguments as determined by the format. It returns the number of items successfully parsed.

Golang fmt.Sscanf() function usage example

 package main

 import "fmt"

 func main() {

 str := "我的名字是 (my name is) : Golang , I'm 5 years old now"

 var name string
 var age int

 // WARNING : the comma must be separated by a space
 // %s , OK
 // %s, NOT OK

 fmt.Sscanf(str, "我的名字是 (my name is) : %s , I'm %d years old now", &name, &age)
 fmt.Printf("%s %d\n", name, age)
 }

Output :

Golang 5

Reference :

http://golang.org/pkg/fmt/#Sscanf

Advertisement