+ 1
How can i do this?
I want to change string values which only contains numbers into integers or floats in go. Like using the int() in Python ? If you know please tell me
1 Antwort
+ 1
As Mirielle said the package "strconv" is a good approach.
https://golang.org/pkg/strconv/#hdr-Numeric_Conversions
Or with fmt.SscanXXX
https://golang.org/pkg/fmt/#Sscanln
text := "12345"
var n int
if _, err := fmt.Sscanln(text, &n); err != nil {
panic(err)
}
fmt.Println(str, n)
Some types also accept direct conversion using type as function call...
chars := []rune("We are GOing to learn")