Converting the characters in a string to uppercase is easy to do in Ruby. We can achieve this with the upcase
method. But this won’t modify the string permanently. However, with the upcase!
method, we can permanently change lowercase characters present in a string to their uppercase equivalent.
str.upcase!
str: this is the string whose characters we want to permanently change to uppercase
A new string is returned which is the uppercase of characters present in string str
. However, if all or any of the characters are uppercase, nothing will be changed.
# create some strings str1 = "edpresso" str2 = "IS" str3 = "grEAt!" # to uppercase str1.upcase! str2.upcase! str3.upcase! # print strings puts str1 puts str2 puts str3
upcase!
method was called on the strings created.As you can see, the characters in the strings were permanently changed to uppercase characters.
RELATED TAGS
CONTRIBUTOR
View all Courses