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