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

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]
主站蜘蛛池模板: 卢龙县| 安远县| 聊城市| 吉木萨尔县| 内黄县| 龙川县| 盐亭县| 宜良县| 宜城市| 上林县| 揭东县| 广昌县| 区。| 荔浦县| 无棣县| 杭州市| 思南县| 新和县| 杂多县| 旬阳县| 成都市| 乾安县| 吐鲁番市| 鄂州市| 共和县| 福鼎市| 龙川县| 桑日县| 吉林省| 遂平县| 咸宁市| 梅州市| 离岛区| 合水县| 时尚| 岫岩| 太仆寺旗| 南溪县| 正宁县| 富民县| 新郑市|