常见问题解答:在 Raku 中,如何检查String https://docs.perl6.org/type/Str包含子字符串 ?在哪里以及多少次?
我想要 3 个功能,例如:
xxx-bool("az and az and az again", "az"); # True
xxx-num("az and az and az again", "az"); # 3
xxx-list("az and az and az again", "az"); # (0 7 14)
PS:日常index https://docs.perl6.org/type/Str#routine_index and rindex https://docs.perl6.org/type/Str#routine_rindex很酷,但只得到一场比赛。
相关链接:
- 用正则表达式回答 https://stackoverflow.com/questions/49596244
- 列表上的答案(数组) https://stackoverflow.com/questions/41763453
- 列表上的连续序列 https://stackoverflow.com/questions/5926655
- 关于哈希的答案(字典) https://stackoverflow.com/questions/54520727
- 要检查它是否包含,请使用.包含 https://docs.perl6.org/type/Str#method_contains得到一个Bool https://docs.perl6.org/type/Bool这是一个cool https://docs.perl6.org/type/Cool method https://docs.perl6.org/type/Method.
- 要获取索引(别名索引:两者都是索引的复数),请使用.indices https://docs.perl6.org/type/Str#method_indices
- 要获得数字,请计算索引。
"az and az and az again".contains("az"); # True
"az and az and az again".indices("az").elems; # 3
"az and az and az again".indices("az"); # (0 7 14)
PS:日常indices https://docs.perl6.org/type/Str#method_indices紧接着描述index https://docs.perl6.org/type/Str#routine_index and rindex https://docs.perl6.org/type/Str#routine_rindex。因此,请阅读好文档,并仔细阅读它;-)
-
Links:
- 包含在正则表达式中 https://stackoverflow.com/questions/47051427
- 同样的问题在Python https://stackoverflow.com/questions/3437059, Perl https://stackoverflow.com/questions/7283274
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)