网站源码本地演示,人人设计网网址,微帮推广平台怎么加入,怎样做游戏网站在 Go 中字符串是不可变的#xff0c;例如下面的代码编译时会报错#xff1a; cannot assign to s[0] 但如果真的想要修改怎么办呢#xff1f;下面的代码可以实现#xff1a; var s string hello s [ 0 ] c s : hello c : [] b… 在 Go 中字符串是不可变的例如下面的代码编译时会报错 cannot assign to s[0] 但如果真的想要修改怎么办呢下面的代码可以实现 var s string hello s [ 0 ] c s : hello c : [] byte ( s ) // 将字符串 s 转换为 []byte 类型 c [ 0 ] c s2 : string ( c ) // 再转换回 string 类型 fmt . Printf ( %s\n , s2 ) 字符串不能直接修改但是可以进行切片操作 s aas[1:]