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
+12.8k Golang : convert(cast) string to float value
+23.6k Golang : Get current file path of a file or executable
+11.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+3.1k Detect if Google Analytics and Developer Media are loaded properly or not
+8.6k Golang : How to check if a website is served via HTTPS
+5.6k Golang : Spell checking with ispell example
+13.1k Golang : How to get URL port?
+16.4k Golang : How to log each HTTP request to your web server?
+14.8k Golang : Read integer from file into array
+14.7k Golang : Read a file line by line
+5.5k Nginx : Password protect a directory/folder
+3.9k MariaDB/MySQL : Form select statement or search query with Chinese characters