文字列を区切って配列にする String.split
ひとことで言うと
区切り文字で文字列を分割する。
ブロックとコード
""を","で分割
ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。
"".split(",")"".split(",")引数(ひきすう)
引数とは、ブロックの中で自分で選んだり入力したりする部分のことです。
| 名前 | 選べる値 | 意味 |
|---|---|---|
| separator | 文字列 | @param limit |
| limit | 数値 |
使用例
If a string contains a list of animals and those animal names each end with a comma, that comma can be the separator.
JavaScript
let animals = "giraffe,lion,wolf,hippo,cat,racoon"Python
animals = "giraffe,lion,wolf,hippo,cat,racoon"When the animals string is split using the comma, an array of animal names is created.
JavaScript
let animals = "giraffe,lion,wolf,hippo,cat,racoon"
let animalNames = animals.split(",")Python
animals = "giraffe,lion,wolf,hippo,cat,racoon"
animalNames = animals.split(",")If you wanted to get the "hippo" string, just select the string from animalNames at the index of 3.
JavaScript
let animals = "giraffe,lion,wolf,hippo,cat,racoon"
let animalNames = animals.split(",")
let hippo = animalNames[3]Python
animals = "giraffe,lion,wolf,hippo,cat,racoon"
animalNames = animals.split(",")
hippo = animalNames[3]