- 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]
推薦閱讀
- 黑客攻防從入門到精通(實戰秘笈版)
- Mastering RabbitMQ
- 云原生Spring實戰
- C語言最佳實踐
- 零基礎學Java(第4版)
- Kinect for Windows SDK Programming Guide
- Oracle Exadata專家手冊
- SQL Server數據庫管理與開發兵書
- Building Microservices with .NET Core
- Flowable流程引擎實戰
- Android傳感器開發與智能設備案例實戰
- C語言程序設計實訓教程與水平考試指導
- 分布式數據庫原理、架構與實踐
- Penetration Testing with the Bash shell
- Pandas 1.x Cookbook