Golang – Convert a string to an integer

To convert a string to an integer with Golang, the Google programming language, you must use the Atoi function of the strconv package.

Here is an example:

package main

import (
    "fmt"   
    "strconv"    
    )
    
func main() {
    
    mystring := "1"
    myinteger := 1
    myconvertedstring, _ := strconv.Atoi(mystring)
    fmt.Println(myconcertedstring + myinteger )
    
}

Leave a Comment

Your email address will not be published. Required fields are marked *