Ruby How to convert between uppercase and lowercase

Introduction

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

downcase method

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

Ruby How to convert between uppercase and lowercase
[Ruby] How to convert from lowercase to uppercase and from uppercase to lowercase
[Java] Convert character strings to uppercase / lowercase (AOJ⑨-swap uppercase and lowercase)
How to convert LocalDate and Timestamp
[Easy] How to upgrade Ruby and bundler
Convert JSON to TSV and TSV to JSON with Ruby
[IntelliJ IDEA] How to display code completion candidates without distinguishing between uppercase and lowercase letters
[Ruby] How to convert CSV file to Yaml (Yml)
[Ruby] How to use gsub method and sub method
How to convert A to a and a to A using AND and OR in Java
How to handle TSV files and CSV files in Ruby
[Ruby] How to get the tens place and the ones place
(Ruby on Rails6) How to create models and tables
How to use Ruby return
Convert to Ruby Leet string
[Ruby] How to comment out
Ruby: How to use cookies
[Ruby] How to write blocks
How to convert Java radix
Difference between Java and JavaScript (how to find the average)
[Rails] Differences between redirect_to and render methods and how to output render methods
Differences in how to handle strings between Java and Perl
How to dynamically switch between FIN and RST in Netty
How to deal with different versions of rbenv and Ruby
[Ruby] How to batch convert strings in an array to numbers
[Ruby] How to get the value by specifying the key. Differences between hashes, symbols and fetch
[Ruby] Difference between get and post
Convert ruby object to JSON format
How to use EventBus3 and ThreadMode
How to install ruby through rbenv
How to use Ruby on Rails
How to convert erb file to haml
How to call classes and methods
How to use equality and equality (how to use equals)
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
How to connect Heroku and Sequel
How to use Ruby inject method
How to execute Ruby irb (interactive ruby)
Offline real-time how to write F03 ruby and C implementation example
[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
How to Synchronize Customer Data Between Salesforce and Kintone (Java-Simple JDBC)
How to get and add data from Firebase Firestore in Ruby
[Java] How to convert from String to Path type and get the path
Easy to understand the difference between Ruby instance method and class method.
Note: Difference between Ruby "p" and "puts"
How to get date data in Ruby
How to use OrientJS and OrientDB together
[Ruby on Rails] How to use CarrierWave
[Rails] How to convert from erb to haml
Difference between Ruby instance variable and local variable
Convert numbers to Roman numerals in Ruby
[Core ML] How to convert YOLO v3 to Core ML
[Java] How to output and write files!
How to set up and use kapt
How to build SquashTM and how to support Japanese
How to convert java.util.Date, java.sql.Date, LocalDate, ZonedDateTime
How to find the tens and ones
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
[Ruby on Rails] How to use kaminari
How to use substring and substr methods