+ 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

6th May 2021, 9:58 AM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
2 odpowiedzi
+ 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")
6th May 2021, 11:10 AM
David Ordás
David Ordás - avatar