perl

perl trim

sub trim {
    my($string)=$_[0];
    if(exists $_[1]){$reg=$_[1];}else{$reg='\s';}
    for ($string) {
        s/^$reg+//;
        s/$reg+$//;
    }
    return $string;
}
 
# Example trim($text);
# Example trim($text,"\|");