Here,there are methods about case of string in Ruby language.
1.String#upcase
2.String#upcasedowncase
3.String#swapcase
4.String#capitalize
5.String#capitalize_first_letter
All four methods have corresponding methods that modify a string in place rather than creating a new one: upcase!, downcase!, swapcase!, and capitalize!. Assuming you don't need the original string, these methods will save memory, especially if the string is large.
To change the case of specific letters while leaving the rest alone, you can use the TR or TR! methods, which translate one character into another:
'LOWERCASE ALL VOWELS'.tr('AEIOU', 'aeiou')
# => "LoWeRCaSe aLL VoWeLS"
没有评论:
发表评论