This time, we will do a method to convert a character string from uppercase to lowercase in Ruby!
Method used this time -Convert uppercase to lowercase with downcase -Convert lowercase letters to uppercase with upcase ・ Convert between lowercase letters and uppercase letters with swapcase ・ Convert the first lowercase letter to uppercase with capitalize
The downcase method is a method used when you want to convert uppercase letters contained in a character string to lowercase letters.
String.downcase
str = "Hello World"
puts str.downcase
[Output result]
hello world
upcase The upcase method is a method used when you want to convert uppercase letters contained in a character string to lowercase letters.
String.upcase
str = "Hello World"
puts str.upcase
[Output result]
HELLO WORLD
swapcase The swapcase method is a method that swaps uppercase and lowercase letters in a character string.
String.swapcase
str = "Hello World"
puts str.swapcase
[Output result]
hELLO wORLD
capitalize capitalizeh is a method that converts the first lowercase letter to uppercase
String.capitalize
str = "hello world"
puts str.capitalize
[Output result]
Hello World
Recommended Posts