0
0

More than 3 years have passed since last update.

【Ruby】文字列で使用出来るメソッド調べてみました①

Last updated at Posted at 2019-11-18

※初めての投稿ですm(__)m

文字列の定義


文字列(String)の指定はダブルクオーテーション("")で文字列を囲うことで定義出来ます。
sample.rb
変数 = "文字列"

分割する

split(文字列の分割)

sample.rb
string = "pockemon, ruby, pikachu"
p string.split(",")
=> ["pockemon", " ruby", " pikachu"]

変換する

capitalize, capitalize!(先頭の文字を大文字に変換する)

sample.rb
string = "poCkemon, pikachU"
p string.capitalize
=> "Pockemon, pikachu"

reverse, reverse!(文字列を反転する)

sample.rb
string = "pockemon"
p string.reverse
=> "nomekcop"

downcase, downcase!(大文字を小文字に変換する)

sample.rb
string = "POCKEMON, pikachU"
p string.downcase
=> "pockemon, pikachu"

upcase, upcase!(小文字を大文字に変換する)

sample.rb
string = "pockemon, pikachu"
p string.upcase
=> "POCKEMON, PIKACHU"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0