1

如何仅将字符串的偶数字母大写?

我试过了:

str = "apples"; str.capitalize
4

2 回答 2

3
"abcdefgh".gsub /..?/, &:capitalize
=> "AbCdEfGh"

"abcdefgh".gsub /(?!^)..?/, &:capitalize
=> "aBcDeFgH"

Use string.gsub! instead of string.gsub if you want to modify your original string.

于 2012-07-16T12:06:47.337 回答
0
string.scan(/..?/).map(&:capitalize) * ''
于 2012-07-16T06:56:02.680 回答