1
是否有downcase一个子比这个?:红宝石子downcase
string[a..b] = string[a..b].downcase
也许这样的事情更合适的方式:
string[a..b].downcase!
例如:
string = "RubyChangedMyMind"
string[1..string.length] = string[1..string.length].downcase
# this is working but i want to know if there is more short way to do this
# (indeces may be different)
# something like string[a..b].downcase!
你想完成什么目前还不清楚。你能显示一个样本字符串,你想要结果是什么?这似乎在做预期的事情。 – vgoff
你能举一个你想要的例子吗? – Dschoni
['String#[]'](http://ruby-doc.org/core-2.3.1/String.html#method-i-5B-5D)总是返回一个_new_字符串(或'nil')。因此更改该字符串不会影响原始字符串。根据你的用例,你可以使用'sub!'和一个正则表达式。 – Stefan