在Go语言中将int和long转换为字符串

7

我有一个并发程序,像这样:

Routine 1()
{
for 30 times
Send string
}

Routine 2 (out <-chan string)
{
for
case str := <- out:
        fmt.Println(str)
}

现在,我想从程序1发送一个字符串,例如,字符串+整数+字符串+纳秒级系统时间。有人能帮我实现这个吗?

我实际上在询问,在Go中是否可以执行 out <- string + strconv.Itoa(int) + string(strconv.Itoa64(time.Nanoseconds()))? - Arpssss
1个回答

10

抱歉,我提问得太早了。可以像这样实现:

out <- string + strconv.Itoa(int) + string + strconv.Itoa64(time.Nanoseconds())

感谢。


更新(Go1):strconv.Itoa64 已被替换为 strconv.FormatInt


4
这样写也可以:out <- fmt.Sprintf("blah %d blah %d", someint, time.Now().UnixNano()) - jimt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接