string to int conversion

1,716 views
Skip to first unread message

abiosoft

unread,
Nov 30, 2009, 10:29:30 AM11/30/09
to golang-nuts
I've searched the tutorials but couldn't find a way to convert string
to integer. what function will i use?

roger peppe

unread,
Nov 30, 2009, 10:33:30 AM11/30/09
to abiosoft, golang-nuts
see Atoi in the strconv package

2009/11/30 abiosoft <abio...@gmail.com>:

Dean Sinaean

unread,
Apr 9, 2012, 9:28:10 AM4/9/12
to golan...@googlegroups.com, abiosoft


在 2009年11月30日星期一UTC下午3时33分30秒,rog写道:
see Atoi in the strconv package
I used Sscanf to do this. @abiola89: could you tell me what is the difference between the two? or just tell me which one is better( more efficient).Many thanks! 

sdeg...@8thlight.com

unread,
Apr 9, 2012, 10:25:03 AM4/9/12
to golan...@googlegroups.com
strconv.ParseInt()

http://golang.org/pkg/strconv/#ParseInt

-Steven

Steven Blenkinsop

unread,
Apr 9, 2012, 11:17:11 AM4/9/12
to Dean Sinaean, golan...@googlegroups.com, abiosoft
Sscanf uses Atoi once it has parsed the format string and figured out the type of the corresponding parameter. Using Atoi directly bypasses that as long as you know you have the string representation of an int.
Reply all
Reply to author
Forward
0 new messages