Golang : convert(cast) string to integer value
To convert or cast a string to integer value, just use the strconv.Atoi()
function. Below is the code example to demonstrate how to convert string to integer value.
package main
import (
"fmt"
"strconv"
)
func main() {
var i int
i, _ = strconv.Atoi("123")
fmt.Println(i)
}
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.8k Golang : Transform comma separated string to slice example
+13.1k Golang : concatenate(combine) strings
+9.5k Android Studio : Simple input textbox and intercept key example
+17.7k Unmarshal/Load CSV record into struct in Go
+5.1k Unix/Linux : How to open tar.gz file ?
+7.6k PHP : How to parse ElasticSearch JSON ?
+6.1k CloudFlare : Another way to get visitor's real IP address
+9.2k Golang : Convert octal value to string to deal with leading zero problem
+11k Golang : Perform sanity checks on filename example
+15.8k Golang : Set up source IP address before making HTTP request
+26.1k Golang : dial tcp: too many colons in address
+23.2k Golang : Generate MD5 checksum of a file