2016-03-02 17:15
浏览 946

如何在Go lang的uint16中转换字符串值?

I'm researching a solution in order to convert a string (in my case the string is "05f8") into a uint16.I made research but I don't find a solution.Does anyone know how to do this?

Thanks for your help!

图片转代码服务由CSDN问答提供 功能建议

我正在研究一种解决方案,以便将字符串(在我的情况下,字符串为“ 05f8”)转换为 我做了研究但没有找到解决方案。有人知道怎么做吗?


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douchilian1009 2016-03-02 17:25

    Use strconv.ParseUint (doc).

    var s = "05f8"
    var base = 16
    var size = 16
    value, err := strconv.ParseUint(s, base, size)

    Note that the output value is an uint64, you have to cast it to you type before using it.

    Note (bis) that the size parameter control the maximum size of the uint to convert to, so the overflow check is done correctly.

    打赏 评论

相关推荐 更多相似问题