如何在 Go 中将 int 值转换为字符串?

如何在 Go 中将 int 值转换为字符串?

问题描述:

i := 123
s := string(i) 

s 是E",但我想要的是123"

s is 'E', but what I want is "123"

请告诉我如何获得123".

Please tell me how can I get "123".

而在 Java 中,我可以这样做:

And in Java, I can do in this way:

String s = "ab" + "c"  // s is "abc"

如何在 Go 中concat 两个字符串?

how can I concat two strings in Go?

使用strconv 包的 Itoa 函数.

例如:

package main

import (
    "strconv"
    "fmt"
)

func main() {
    t := strconv.Itoa(123)
    fmt.Println(t)
}

您可以简单地通过 + 连接字符串,或者使用 strings 包.

You can concat strings simply by +'ing them, or by using the Join function of the strings package.