Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string to *uint64 in golang

Assume there is a string holding the address of an uint64 type variable, can we parse this address back to an *uint64?

For example:

i := uint64(23473824)
ip := &i
str := fmt.Sprintf("%v", ip)

u, _ := strconv.ParseUint(str, 0, 64)

u is uint64. How to get pointer out of this value?

Playground link: https://play.golang.org/p/1KXFQcozRk

like image 280
ecem Avatar asked Mar 10 '15 15:03

ecem


1 Answers

It is as simple as:

number, err := strconv.ParseUint(string("90"), 10, 64)

then do some error checking, hope it helps.

like image 129
Eduardo A EDUARDO Fernandez Di Avatar answered Sep 21 '22 11:09

Eduardo A EDUARDO Fernandez Di