Go字符类型转化为整型或者整型转化为字符类型

版权声明:本文为博主John Lau原创文章,未经博主允许不得转载 https://blog.csdn.net/GreatElite/article/details/78849856

Go语言很容易地实现了字符类型到整型类型的转化,反过来也一样。见下文代码实现。

    i := 10
    fmt.Printf("i convert string : %s", strconv.Itoa(i))

    s := "1000"
    // The bitSize argument specifies the integer type
    // that the result must fit into. Bit sizes 0, 8, 16, 32, and 64
    // correspond to int, int8, int16, int32, and int64.
    if v , err := strconv.ParseInt(s, 10, 0); err != nil {
        fmt.Errorf("\n strconv.ParseInt %s\n", err.Error())
    }else {
        fmt.Printf("string s convert int64 : %d", v)
    }

欢迎加入我的微信公众号

欢迎加入我的微信公众号

猜你喜欢

转载自blog.csdn.net/GreatElite/article/details/78849856