String to uint32

8,186 views
Skip to first unread message

Joan Miller

unread,
Apr 8, 2010, 8:57:24 AM4/8/10
to golang-nuts
How to convert a string to uint32?

The library `strconv` has not a function to convert to uint32
else to uint64 and uint

Lambda

unread,
Apr 8, 2010, 9:04:39 AM4/8/10
to golang-nuts
func Atoui(s string) (i uint, err os.Error)
func Atoui64(s string) (n uint64, err os.Error)

There is no Atoui32, maybe for some reasons.

peterGo

unread,
Apr 8, 2010, 9:23:21 AM4/8/10
to golang-nuts
Joan,

Read the replies to your messages form yesterday. You would see:

if bar, err := strconv.Atoui(t[1]); err == nil {
f.bar = uint32(bar)
}

Peter

Mosleh Saeidi

unread,
May 22, 2021, 6:26:29 PM5/22/21
to golang-nuts
so what is the solution, I have a variable type is uint32, and now want to convert a string to that variable ?

Ian Lance Taylor

unread,
May 22, 2021, 6:36:30 PM5/22/21
to Mosleh Saeidi, golang-nuts
On Sat, May 22, 2021 at 3:26 PM Mosleh Saeidi <mosleh...@gmail.com> wrote:
>
> so what is the solution, I have a variable type is uint32, and now want to convert a string to that variable ?

Note that you are replying to a message written in 2010.

To convert a string to an integer see https://golang.org/pkg/strconv/#ParseInt .

Ian

peterGo

unread,
May 22, 2021, 8:45:29 PM5/22/21
to golang-nuts
On Saturday, May 22, 2021 at 6:26:29 PM UTC-4 Mosleh Saeidi wrote:
so what is the solution, I have a variable type is uint32, and now want to convert a string to that variable ?

peterGo

unread,
May 22, 2021, 8:53:30 PM5/22/21
to golang-nuts
On Saturday, May 22, 2021 at 6:36:30 PM UTC-4 Ian Lance Taylor wrote:
On Sat, May 22, 2021 at 3:26 PM Mosleh Saeidi <mosleh...@gmail.com> wrote:
>
> so what is the solution, I have a variable type is uint32, and now want to convert a string to that variable ?

To convert a string to an integer see https://golang.org/pkg/strconv/#ParseInt .

Ian


For unsigned integers, s/ParseInt/ParseUint/

Peter
 
Reply all
Reply to author
Forward
0 new messages