Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何仅将字符串的偶数字母大写?
我试过了:
str = "apples"; str.capitalize
"abcdefgh".gsub /..?/, &:capitalize => "AbCdEfGh" "abcdefgh".gsub /(?!^)..?/, &:capitalize => "aBcDeFgH"
Use string.gsub! instead of string.gsub if you want to modify your original string.
string.gsub!
string.gsub
string.scan(/..?/).map(&:capitalize) * ''