How to convert []int8 to string

后端 未结 4 947
失恋的感觉
失恋的感觉 2020-12-11 05:04

What\'s the best way (fastest performance) to convert from []int8 to string?

For []byte we could do string(byteslice), but for

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 05:38

    Use unsafe package.

    func B2S(bs []int8) string {
      return strings.TrimRight(string(*(*[]byte)unsafe.Pointer(&bs)), "\x00")
    }
    

    Send again ^^

提交回复
热议问题