Strings in Golang is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding. In Go language, both signed and unsigned integers are available in four different sizes. In order to convert string to integer type in Golang, you can use the following methods.
1. Atoi() Function: The Atoi stands for ASCII to integer and returns the result of ParseInt(s, 10, 0) converted to type int.
func Atoi(s string) (int, error)
123 0 strconv.Atoi: parsing "12.3": invalid syntax
2. ParseInt() Function: The ParseInt interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.
func ParseInt(s string, base int, bitSize int) (i int64, err error)
51 0 strconv.ParseInt: parsing "123": invalid syntax
- How to Convert string to float type in Golang?
- Converting a string variable into Boolean, Integer or Float type in Golang
- Different Ways to Convert the Boolean Type in String in Golang
- Different Ways to Convert an Integer Variable to String in Golang
- How to convert Int data type to Float in Golang?
- Searching an element of string type in Golang slice
- How to fetch an Integer variable as String in GoLang?
- How to convert a string in uppercase in Golang?
- How to convert a string in lower case in Golang?
- How to Convert a zero terminated byte array to string in Golang?
- Type Casting or Type Conversion in Golang
- Type Switches in GoLang
- Type Assertions in Golang
- How to Get Int Type Random Number in Golang?
- How to find the type of Struct in Golang?
- How to add a method to struct type in Golang?
- How to Get Int31n Type Random Number in Golang?
- How to Get Int63n Type Random Number in Golang?
- How to Get Uint32 Type Random Number in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.