Mih*_*yan 8 string perl substring
如果是perl的问题.
例如,如果我有"hello.world"和指定的字符是'.'我想要的结果"hello".
Jim*_*vis 26
$x = "hello.world";
$y = substr($x, 0, index($x, '.'));
Run Code Online (Sandbox Code Playgroud)
使用substr:
my $string = "hello.world";
my $substring = substr($string, 0, index($string, "."));
Run Code Online (Sandbox Code Playgroud)
或者使用正则表达式:
my ($substring2) = $string =~ /(.*)?\./;
Run Code Online (Sandbox Code Playgroud)