5

What's the function to create a int value from string

i := ???.????( "10" )
OscarRyz
  • 196,001
  • 113
  • 385
  • 569

2 Answers2

8

Import the strconv package (src/pkg/strconv), then use strconv.Atoi("10")

Kyle Rosendo
  • 25,001
  • 7
  • 80
  • 118
0

Some other options:

package main
import "fmt"

func main() {
   var n int
   fmt.Sscan("100", &n)
   fmt.Println(n == 100)
}
package main
import "strconv"

func main() {
   n, e := strconv.ParseInt("100", 10, 64)
   if e != nil {
      panic(e)
   }
   println(n == 100)
}
Zombo
  • 1
  • 62
  • 391
  • 407