Logo

Programming-Idioms

History of Idiom 22 > diff from v16 to v17

Edit summary for version 17 by :

Version 16

2015-08-21, 23:10:54

Version 17

2015-08-21, 23:11:12

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, err  := 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.
Doc URL
http://golang.org/pkg/strconv/
Doc URL
http://golang.org/pkg/strconv/#Atoi
Demo URL
http://play.golang.org/p/VXjGHZbj6J
Demo URL
http://play.golang.org/p/VXjGHZbj6J