How to check if a String is an Integer in Go Language
Hello everyone, in this tutorial, we’ll explore multiple ways to detect if the given String is an int. Example 1: Using strconv.Atoi() function package main import ( "fmt" "strconv" ) func main() { str1 := "5674" str2 := "123o" fmt.Println(IsInt(str1)) fmt.Println(IsInt(str2)) } func IsInt(str string ) bool { _, err := strconv.Atoi(str) if err != nil { return false } else { return true } } Output: Author: Joy More Related Topics, How to make a delay in Go Language Program to check if a string contains the substring How to Split a String by Space in Go Language? Trigonometry with Go - Sin, Cos, Tan Functions Examples How to iterate over a map in Go? Go Arrays - Program to Find Largest & Smallest Element Go Arrays - Program to find the duplicate elements of an Array Go - Factorial Program using loop Go - Palindrome Program Example Go Program to print Odd and Even Numbers from an ...