Convert []string to []byte

后端 未结 6 1694
梦谈多话
梦谈多话 2021-02-07 01:36

I am looking to convert a string array to a byte array in GO so I can write it down to a disk. What is an optimal solution to encode and decode a string array ([]string

6条回答
  •  粉色の甜心
    2021-02-07 02:42

    to convert []string to []byte

    var str = []string{"str1","str2"}
    var x = []byte{}
    
    for i:=0; i

    to convert []byte to string

    str := ""
    var x = []byte{'c','a','t'}
    for i := 0; i < len(x); i++ {
        str += string(x[i])
    }
    

提交回复
热议问题