Cheatsheet collection for go, rust, python, shell and javascript.

Parse String to uint in Golang

You can use the strconv package from the Go Standard Library to parse a string into a uint.

The following line of code shows an example of how to use the strconv.ParseUint function to parse a string into a uint:

num, err := strconv.ParseUint(str, 10, 64)

The str argument is the string to be parsed, the 10 argument is the base of the number in the string (in this case 10 for decimal) and the 64 argument is the bit size of the resulting uint (in this case 64).

If the string is successfully parsed into a uint, the err variable will be nil and num will contain the parsed uint.