How do I remove white space in a Perl string?

后端 未结 12 1945
离开以前
离开以前 2020-12-31 09:34

If I declared a variable $myString with the value \'3 \' (notice the white space). Is there any function to remove the white space for the return v

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 09:56

    sub trim($)
    {
        my $string = shift;
        $string =~ s/^\s+//;
        $string =~ s/\s+$//;
        return $string;
    }
    
    
    print trim($myString)
    

提交回复
热议问题