Various Ruby string operations


Keep a record of the problems and answers you solved to study Ruby's string manipulation methods.

Question 1

Convert "This" "is" "a" "pen" to "This is a pen".

Answer 1

"This" + " is" + " a" + " pen"


"+" Can concatenate character strings.

Problem 2

Convert "BENZ, BMW, Audi" to ["BENZ", "BMW", "Audi"].

Answer 2

"BENZ, BMW, Audi".split(",")


[] Represents an array. The split method can split a string. If you use it like an answer, you can separate it with a comma.

Problem 3

Convert "apple" to "Apple".

Answer 3



The capitalize method can capitalize the first letter.

Problem 4

Convert "qiita" to "atiiq".

Answer 4



The reverse method can reverse a string.

Problem 5

Convert "Good morning" to "GOOD MORNING".

Answer 5

"Good morning".upcase


The upcase method can convert lowercase letters to uppercase.


Ruby 2.7.0 Reference Manual

Recommended Posts

Various Ruby string operations
Various rails migration operations
Master various migration operations
Ruby four arithmetic operations
[Ruby] Various types of each
Convert to Ruby Leet string
Ruby About various iterative processes
Ruby Learning # 8 Working With String
Cut out a Ruby string
Explanation about Ruby String object
Various methods of Java String class
Ruby standard input and various methods
String output method memo in Ruby
Various methods of the String class
String operations this and that-Java edition-
Extract a part of a string with Ruby