0

プログラムで文字列をそれらの間のスペースで分割したい

$string = "hello how are you";  

出力は次のようになります。

hello  
how  
are  
you
4

5 に答える 5

4

シンプルに思うのですが……。

$string = "hello how are you";  
print $_, "\n" for split ' ', $string;
于 2013-06-25T11:27:01.110 に答える
2

@Array = split(" ",$string);次に、@Array答えが含まれています

于 2013-06-25T10:58:08.480 に答える
0

余分なスペースがある場合は、正規表現で分割します。

my $string = "hello how are you";
my @words = split /\s+/, $string; ## account for extra spaces if any
print join "\n", @words
于 2013-06-25T13:31:05.687 に答える
0

文字列をスペースで分割するには分割が必要です

use strict;

my $string = "hello how are you";

my @substr = split(' ', $string); # split the string by space

{
  local $, = "\n"; # setting the output field operator for printing the values in each line
  print @substr;
}

Output:

hello
how
are
you
于 2013-06-25T11:01:03.163 に答える