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
+18.5k Golang : Read binary file into memory
+5.4k Golang : Generate Interleaved 2 inch by 5 inch barcode
+24.1k Golang : Use regular expression to validate domain name
+9.3k Golang : Create and shuffle deck of cards example
+17.7k Golang : Parse date string and convert to dd-mm-yyyy format
+21.9k Golang : How to reverse slice or array elements order
+30k Golang : How to get HTTP request header information?
+7.2k Golang : Squaring elements in array
+5.3k JavaScript/JQuery : Redirect page examples
+15.7k Golang : Validate hostname
+29.7k Golang : Saving(serializing) and reading file with GOB
+4.8k PHP : Extract part of a string starting from the middle