LoginSignup
0
0

More than 3 years have passed since last update.

文字列を配列に入れる方法

Last updated at Posted at 2020-11-20

splitメソッド

文字列に使うことのできるメソッド。
文字列を分割して、配列に入れる事ができる。

str = "Ruby PHP"
ary = str.split(' ') #半角の空白で区切る時は、ちゃんと半角の空白を作る。(半角空白で区切る場合は、引数の省略可)
#=>ary = ["Ruby","PHP"]

('')空白で区切ったり、(,)カンマで区切ったりを引数で指定できる。

配列にすることで、使う事ができるメソッドが変わる。
getsで入力されたものを配列に入れるときにも使える。

0
0
2

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