Free coupon for initial registration

Split string by separator and output them

Contents [hide]

Output

a
b
c


Code examples


JavaScript

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

Perl

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

PHP

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

Python

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

Ruby

1
2
3
4
5
str = "a,b,c"
array = str.split(",")
for elem in array
    print(elem+"\n")
end
Free coupon for initial registration