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 :
Advertisement
Something interesting
Tutorials
+11.8k Golang : convert(cast) float to string
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+18.7k Golang : convert int to string
+8.6k Golang : Set or add headers for many or different handlers
+9.7k Golang : interface - when and where to use examples
+6.1k nginx : force all pages to be SSL
+23.5k Golang : Check if element exist in map
+17.7k How to enable MariaDB/MySQL logs ?
+8.2k Golang : Get final or effective URL with Request.URL example
+36.5k Golang : Validate IP address
+9.7k Golang : Populate slice with sequential integers example
+11.5k Golang : Generate DSA private, public key and PEM files example