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

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]
主站蜘蛛池模板: 新泰市| 怀宁县| 无为县| 阜阳市| 科技| 社会| 崇阳县| 乌拉特后旗| 徐水县| 江门市| 湾仔区| 罗田县| 昌乐县| 安图县| 灵寿县| 安义县| 西藏| 右玉县| 漳平市| 长沙市| 嘉祥县| 福州市| 大渡口区| 大化| 泰州市| 靖西县| 兴文县| 清徐县| 昌邑市| 崇明县| 竹溪县| 襄城县| 巴东县| 桦南县| 通河县| 青铜峡市| 稷山县| 香格里拉县| 平陆县| 阿克苏市| 石嘴山市|