Go:字符串与数组切片相互转换

在下述举例中我们使用:字符串数组words=["hello","world","xx"],字符数组word=['h','e','l','l','o'],字符串s="hello world"


  • 字符串数组 []string 转为 字符串 string

s := strings.Join(words,"")

  • 字符数组 []byte 转为 字符串 string

s := string(word)

  • 字符串 string 转为 字符串数组

words := strings.Split(s," ")

  • 字符串 string 转为 字符数组 []byte

word := []byte(s)

posted on 2023-08-21 11:32  shui00cc  阅读(139)  评论(0编辑  收藏  举报