Programming-Idioms

History of Idiom 22 > diff from v5 to v6

Edit summary for version 6 :

Version 5

2015-08-01, 16:39:13

Version 6

2015-08-03, 22:57:56

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Imports
import "strconv"
Imports
import "strconv"
Code
i, _  := strconv.Atoi(s) 
Code
i, err  := strconv.Atoi(s) 
Comments bubble
Atoi(s) is shorthand for ParseInt(s, 10, 0). It yields type int.
Comments bubble
Atoi(s) is shorthand for ParseInt(s, 10, 0). It yields type int.
Origin
http://golang.org/pkg/strconv/
Origin
http://golang.org/pkg/strconv/
Demo URL
http://play.golang.org/p/VXjGHZbj6J
Demo URL
http://play.golang.org/p/VXjGHZbj6J