- 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]
推薦閱讀
- Unreal Engine Physics Essentials
- 程序設計與實踐(VB.NET)
- Java面向對象思想與程序設計
- Django Design Patterns and Best Practices
- Django:Web Development with Python
- C語言程序設計案例式教程
- 21天學通C++(第6版)
- 差分進化算法及其高維多目標優化應用
- Java性能權威指南(第2版)
- JSP開發案例教程
- Nexus規模化Scrum框架
- Unity UI Cookbook
- AIRIOT物聯網平臺開發框架應用與實戰
- 深度學習:Java語言實現
- SSM開發實戰教程(Spring+Spring MVC+MyBatis)