官术网_书友最值得收藏!

Methods to cut strings

The two methods—chop and chomp—have similar names but have a different sensitivity to the characters they work with. The chop method cuts out the last character of the string. The chomp method only cuts the last character if it is a newline character.

say "Text\n".chomp; # Text
say "Text\n".chop; # Text

say "Text".chomp; # Text
say "Text".chop; # Tex

Another group of methods—trim, trim-leading, and trim-trailing—cuts the spaces at the beginning and/or end of the string. Consider the following code snippet:

my $s = ' word '.trim;
say "[$s]"; # [word]

$s =
' word '.trim-leading;
say "[$s]"; # [word ]

$s =
' word '.trim-trailing;
say "[$s]"; # [ word]
主站蜘蛛池模板: 宾阳县| 乐山市| 新余市| 鲜城| 罗平县| 康定县| 遂溪县| 滁州市| 台州市| 广饶县| 清流县| 多伦县| 富川| 新乡县| 永春县| 绿春县| 江山市| 抚宁县| 岫岩| 武川县| 剑川县| 鱼台县| 敖汉旗| 金川县| 五原县| 天等县| 南和县| 高要市| 定结县| 偏关县| 泗水县| 南召县| 莎车县| 安达市| 临夏市| 泰兴市| 马山县| 米易县| 鸡泽县| 保亭| 阿克陶县|