darjun / blog-comments

博客评论
0 stars 0 forks source link

2021/05/18/youdontknowgo/string/ #15

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

你不知道的 Go 之 string - 大俊的博客

简介 字符串(string)是 Go 语言提供的一种基础数据类型。在编程开发中几乎随时都会使用。本文介绍字符串相关的知识,帮助你更好地理解和使用它。

https://darjun.github.io/2021/05/18/youdontknowgo/string/

asddongmen commented 2 years ago

博主是不是忘记讲还有一种转换的情况是不会涉及 deep copy 的

str1 := "hello, world!"
for _, b := range []byte(str1) {
  fmt.Println(b)
}

此时,str1 从 string 转换为 bytes 也不会涉及内存申请.

darjun commented 2 years ago

@asddongmen 感谢补充