How to use Capitalize In Ruby
Capitalize is used to capitalize the first character of the string while converting the rest to lowercase.
Syntax:
string.capitalize
In the below example,the string first letter is capitalized and the rest to lowercase. After which we store the result in the variable and output the both the original and capitalized string.
# Define a string
string = "GEEKS FOR GEEKS"
# Capitalize the string using capitalize method
capitalized_string = string.capitalize
# Output the result
puts "Original String: #{string}"
puts "Capitalized String: #{capitalized_string}"
Output
Original String: GEEKS FOR GEEKS Capitalized String: Geeks for geeks
How to Convert a String to Lower or Upper Case in Ruby?
In this article, we will discuss how to convert a string to lower or upper case in Ruby. We can convert a string to lower or upper case using built-in methods provided in the Ruby language.
Table of Content
- Using Downcase
- Using Upcase
- Using Capitalize