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
+22.4k Golang : Match strings by wildcard patterns with filepath.Match() function
+14.7k Golang : How to determine if user agent is a mobile device example
+8.9k Yum Error: no such table: packages
+11.7k SSL : The certificate is not trusted because no issuer chain was provided
+38.4k Golang : Read a text file and replace certain words
+18.8k Golang : Find IP address from string
+29.6k Golang : JQuery AJAX post data to server and send data back to client example
+14.6k Golang : Find network of an IP address
+7.8k Android Studio : AlertDialog to get user attention example
+6.2k Fontello : How to load and use fonts?
+14.5k Golang : Recombine chunked files example
+48.4k Golang : How to convert JSON string to map and slice