文字列を特定の文字で分割して配列に入れ出力

Contents

出力結果

a
b
c

プログラム例

JavaScript

let str = "a,b,c";
let array = str.split(",");
for(i in array) {
    console.log(array[i]);
}

Perl

my $str = "a,b,c";
my @array = split(',', $str);
foreach $elem (@array) {
    print($elem."\n");
}

PHP

<?php
$str = 'a,b,c';
$array = explode(',',$str);
foreach ($array as $elem) {
    print $elem."\n";
}

Python

str = "a,b,c"
array = str.split(",")
for elem in array:
    print(elem)

Ruby

str = "a,b,c"
array = str.split(",")
for elem in array
    print(elem+"\n")
end