- 字符串是不可变,如果想改变,则转为字节数组
x := "text" // x[0] = 'T' // error xtytes := []byte(x) xbytes[0] = 'T' // ok fmt.Println(string(xbytes)) //prints Text
golang 小trick
最新推荐文章于 2022-03-24 18:33:47 发布
x := "text"
// x[0] = 'T' // error
xtytes := []byte(x)
xbytes[0] = 'T' // ok
fmt.Println(string(xbytes)) //prints Text