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

来源:互联网 发布:矩阵谱分解 编辑:程序博客网 时间:2024/05/29 16:13

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)    }

欢迎加入我的微信公众号

欢迎加入我的微信公众号