我正在努力替换字符串中的字符,转换"cat"为"hat".
"cat"
"hat"
这是我的代码:
str = "cat" str[0] = 'h' puts str
但是当我在TryRuby中运行此代码时,我收到此错误:
NoMethodError:未定义的方法`[] ='for"cat"
ruby string replace
replace ×1
ruby ×1
string ×1