string本身是不可变的,因此要改变string中字符,需要如下操作:
str := “hello world” s := []byte(str) s[0] = ‘o’ str = string(s)
1.先改为字符数组
2.修改数组的值
3.数组再转变为字符串
原文地址:https://www.cnblogs.com/guangzhou11/p/10850285.html
时间: 2024-08-02 13:09:58
string本身是不可变的,因此要改变string中字符,需要如下操作:
str := “hello world” s := []byte(str) s[0] = ‘o’ str = string(s)
1.先改为字符数组
2.修改数组的值
3.数组再转变为字符串
原文地址:https://www.cnblogs.com/guangzhou11/p/10850285.html