在Go中将int和long转换为字符串 [英] Converting int and long into string in Go
本文介绍了在Go中将int和long转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的并发例程,
例程1()
{
for 30 times
发送字符串
}
例程2(out <-chan string)
{
for
case str:=< - out:
fmt.Println(str)
}
现在,我想从例程1字符串发送,例如,字符串+ int +字符串+系统时间(纳秒)。任何人都可以帮助我,我该怎么做到这一点。
解决方案对不起,我问得太早。这可能是这样的:
$ $ p $ out< - string + strconv.Itoa(int)+ string + strconv.Itoa64(time .Nanoseconds())
谢谢。
$ b $ p更新(Go1):
strconv.Itoa64
已被替换为 strconv.FormatInt
。 I have concurrent routine like this,
Routine 1()
{
for 30 times
Send string
}
Routine 2 (out <-chan string)
{
for
case str := <- out:
fmt.Println(str)
}
Now, I want to send from routine 1 string like, string + int + string + system time in nanosecond. Can anybody help me how can I achieve this.
解决方案
Sorry, I asked it too early. It is possible like this:
out <- string + strconv.Itoa(int) + string + strconv.Itoa64(time.Nanoseconds())
Thanks.
Update (Go1): strconv.Itoa64
has been replaced by strconv.FormatInt
.
这篇关于在Go中将int和long转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文