Split string by separator and output them

Contents

Output

a
b
c


Code examples


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