SimpleDao
  • strconv.Atoi: Atoi returns the result of ParseInt(s, 10, 0) converted to type int.
  • strconv.ParseInt: ParseInt interprets a string s in the given base (2 to 36) and returns the corresponding value i.
  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. func main() {
  7. str1 := "123"
  8. /** converting the str1 variable into an int using Atoi method */
  9. i1, err := strconv.Atoi(str1)
  10. if err == nil {
  11. fmt.Println(i1)
  12. }
  13. str2 := "456"
  14. /** converting the str2 variable into an int using ParseInt method */
  15. i2, err := strconv.ParseInt(str2, 10, 64)
  16. if err == nil {
  17. fmt.Println(i2)
  18. }
  19. }