Perl:修剪字符串前导和尾随空格的函数 [英] Perl: function to trim string leading and trailing whitespace

查看:58
本文介绍了Perl:修剪字符串前导和尾随空格的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有内置函数来修剪前导和尾随空格,使得 trim(" hello world ") eq "hello world"?

Is there a built-in function to trim leading and trailing whitespace such that trim(" hello world ") eq "hello world"?

推荐答案

这是使用正则表达式的一种方法:

Here's one approach using a regular expression:

$string =~ s/^\s+|\s+$//g ;     # remove both leading and trailing whitespace

Perl 6 将包含修剪功能:

Perl 6 will include a trim function:

$string .= trim;

来源:维基百科

这篇关于Perl:修剪字符串前导和尾随空格的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆