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

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]
主站蜘蛛池模板: 柯坪县| 承德县| 满洲里市| 堆龙德庆县| 车致| 砀山县| 灵山县| 白河县| 时尚| 新闻| 海淀区| 怀来县| 寿光市| 永丰县| 双城市| 通辽市| 电白县| 芜湖县| 定兴县| 双柏县| 会宁县| 江口县| 辉县市| 交城县| 隆安县| 霍邱县| 中宁县| 洛南县| 简阳市| 栖霞市| 普安县| 中江县| 克什克腾旗| 广河县| 玉环县| 赫章县| 白沙| 明溪县| 绵竹市| 鞍山市| 伊川县|