To convert a string to uppercase in Ruby, you can use the upcase()
method of the String class.
In this example,
str1
with a value of "Hello World"
.upcase()
method on str1
to convert it to uppercase.str1
.str1 = "Hello World"
upper_case_str1 = str1.upcase
puts "Uppercase of given string is: #{upper_case_str1}"
Uppercase of given string is: HELLO WORLD
In this example,
str2
with a value of "apple"
.upcase()
method on str2
to convert it to uppercase.str2
.str2 = "apple"
upper_case_str2 = str2.upcase
puts "Uppercase of given string is: #{upper_case_str2}"
Uppercase of given string is: APPLE
In this tutorial, we learned How to convert String to Uppercase in Ruby language with well detailed examples.