2015-09-23 00:12
浏览 292


Maybe a stupid question, but if I have some arbitrary binary data, can I cast it to string and back to byte array without corrupting it?

Is []byte(string(byte_array)) always the same as byte_array?

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

也许是一个愚蠢的问题,但是如果我有一些任意的二进制数据,我可以将其转换为字符串然后返回字节 数组而不破坏它?

[] byte(string(string(byte_array)))是否始终与 byte_array 相同?

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

1条回答 默认 最新

  • dongmeng2509 2015-09-23 00:21

    The expression []byte(string(byte_slice)) evaluates to a slice with the same length and contents as byte_slice. The capacity of the two slices may be different.

    Although some language features assume that strings contain valid UTF-8 encoded text, a string can contain arbitrary bytes.

    打赏 评论

相关推荐 更多相似问题