5

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

i := ???.????( "10" )
OscarRyz
  • 190,799
  • 110
  • 376
  • 555

2 Answers2

8

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

Kyle Rosendo
  • 24,405
  • 7
  • 77
  • 115
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
  • 55
  • 342
  • 375