【问题标题】:Converting int and long into string in Go在 Go 中将 int 和 long 转换为字符串
【发布时间】:2012-04-11 23:18:29
【问题描述】:

我有这样的并发例程,

Routine 1()
{
for 30 times
Send string
}

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

现在,我想从例程 1 中发送字符串,例如字符串 + 整数 + 字符串 + 系统时间(以纳秒为单位)。任何人都可以帮助我如何实现这一目标。

【问题讨论】:

  • 我实际上是在问,Go 中是否有可能输出

标签: go


【解决方案1】:

抱歉,我问得太早了。可能是这样的:

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

谢谢。


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

【讨论】:

  • 或者像这样:out &lt;- fmt.Sprintf("blah %d blah %d", someint, time.Nanoseconds())
  • 感谢 Go1 更新
猜你喜欢
  • 1970-01-01
  • 2016-04-06
  • 2012-04-23
  • 1970-01-01
  • 2020-12-02
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多