Programming in Go

Enums

Casting

String to Integer

package main

import (
"fmt"
"strconv"
)

func main() {

str1 := "1234"

/** converting the str1 variable into an int using Atoi method */
i1, err := strconv.Atoi(str1)
if err == nil {
fmt.Println(i1)
}

str2 := "5678"
/** converting the str2 variable into an int using ParseInt method */
i2, err := strconv.ParseInt(str2, 10, 64)
if err == nil {
fmt.Println(i2)
}
}