[ Perl 6 ] 字符串基础操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[ Perl 6 ] 字符串基础操作相关的知识,希望对你有一定的参考价值。
[ Perl 6 ] 字符串基础操作
There is more than one way to do it.
- 字符串转换为列表:
"banana".comb; # => (b a n a n a)
- 字符串长度:
chars "banana"; "banana".chars; # => 6
- 字符串查找:
index "banana", "na"; # => 2
index "banana", "ni"; # => Nil
index "banana", "na", 3; # => 4
index "banana", "na", 5; # => Nil
rindex "banana", "na"; # => 4
rindex "banana", "na", 3; # => 2
- 字符串子串(起始位置、子串):
substr "I have a dream", 0, 6; # => I have
"I have a dream".substr(9, 5); # => dream
substr "I have a dream", 9, 10; # => dream
substr "I have a dream", *-5; # => dream
- 字符串翻转:
flip "banana"; # => ananab
- 字符串分割(split):
split "-", "2017-09-06"; # => (2017 09 06)
- 字符串连接:
"ba" ~ "na"; # => bana
- 字符串合并(join):
join "-", <I have a dream>; #=> I-have-a-dream
- 字符串大小写改变:
lc "April"; # => "april"
uc "april"; # => "APRIL"
tc "april"; # => "April"
以上是关于[ Perl 6 ] 字符串基础操作的主要内容,如果未能解决你的问题,请参考以下文章