- Perl 6 Deep Dive
- Andrew Shitov
- 126字
- 2021-07-03 00:05:53
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]
推薦閱讀
- SQL Server 從入門到項目實踐(超值版)
- Intel Galileo Essentials
- Redis入門指南(第3版)
- Julia機器學習核心編程:人人可用的高性能科學計算
- Python Geospatial Development(Second Edition)
- 征服RIA
- Android開發:從0到1 (清華開發者書庫)
- Java實戰(第2版)
- 打開Go語言之門:入門、實戰與進階
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- Flink技術內幕:架構設計與實現原理
- Docker:容器與容器云(第2版)
- OpenCV 3.0 Computer Vision with Java
- HTML5與CSS3權威指南
- 軟件測試(慕課版)