i := 123
s := string(i)
s是'E',但我要的是“123”
请告诉我怎样才能得到“123”。
在Java,我可以这样做:
String s = "ab" + "c" // s is "abc"
我如何在Go中concat
两个字符串?
使用strconv
包的itoa
函数。
例如:
package main
import (
"strconv"
"fmt"
)
func main() {
t := strconv.Itoa(123)
fmt.Println(t)
}
您可以简单地通过+
连接字符串,或者使用strings
包的join
函数来连接字符串。