我正在尝试更改 Go 中的现有字符串,但我不断收到此错误“无法分配给 new_str[i]”
package main
import "fmt"
func ToUpper(str string) string {
new_str := str
for i:=0; i<len(str); i++{
if str[i]>='a' && str[i]<='z'{
chr:=uint8(rune(str[i])-'a'+'A')
new_str[i]=chr
}
}
return new_str
}
func main() {
fmt.Println(ToUpper("cdsrgGDH7865fxgh"))
}
这是我的代码,我希望将小写更改为大写,但我无法更改字符串。为什么?我怎样才能改变它?
PS 我希望只使用 fmt 包!
提前致谢。