How do I capitalize only a string's even letters?
如何仅将字符串的偶数字母大写?
I've tried:
str = "apples"; str.capitalize
2 个解决方案
#1
3
"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。
#2
0
string.scan(/..?/).map(&:capitalize) * ''
#1
3
"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。
#2
0
string.scan(/..?/).map(&:capitalize) * ''