Kev*_*rke 9 encoding go
我有这个文本,我想把它放入一个字节切片:
s := "There are these two young fish swimming along and they happen to meet an older fish swimming the other way"
如果我写
b := []byte("There are these two young fish swimming along and they happen to meet an older fish swimming the other way")
据我了解,在运行时,这将:
- 使用内存中的值创建一个字符串
- 创建一个字节切片
- 将字符串的内容复制到字节切片中(根据需要重新分配)
我可以将每个字符串值转换为它们的ASCII等效值并直接创建字节切片:
b := []byte{84, 104, ... }
虽然这不是很易读.
[]byte("blah")