Convert []string to []byte

后端 未结 6 1604
梦谈多话
梦谈多话 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:37

    You can do something like this:

    var lines = []string
    var ctx = []byte{}
    for _, s := range lines {
        ctx = append(ctx, []byte(s)...)
    }
    

提交回复
热议问题