0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

文字列の結合の種類

Posted at

RubySilverの勉強中、文字列の結合のメソッドがいくつか出てきたので備忘録として記していきます。
##文字列の結合
文字列を結合する方法は主に + 演算子とconcatメソッド、<< の3種類あります。
concatと << は破壊的メソッドなのに対し、 + 演算子は非破壊的メソッドです。

+ 演算子の使い方

s1 = Leo 
s2 = Messi

puts s1 + s2
# => LeoMessi

concatの使い方

s1 = Leo
s2 = Messi

s1.concat(s2)

puts s1
# => LeoMessi

<< の使い方

s1 = Leo
s2 = Messi

s1 << s2

puts s1
# => LeoMessi

参考記事
【Ruby】concatを使って文字列や配列を結合する

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?