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