检查字符串是否包含子字符串.此外,获取匹配的索引和数量(乐) [英] Check if a string contains a substring. Additionally, get index and number of match (Raku)
本文介绍了检查字符串是否包含子字符串.此外,获取匹配的索引和数量(乐)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FAQ:在 Raku 中,如何检查 String 是否包含子字符串?在哪里和多少次?我想要 3 个功能,例如:
FAQ: In Raku, how to check if a String contains a substring ? Where and how many times ? I would like 3 functions such as:
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 和rindex 很酷,但只能得到一场比赛.
PS: Routines index and rindex are pretty cool but only get one match.
相关链接:
推荐答案
- To check if it contains, use .contains to get a Bool which is a cool method.
- To get indices (alias indexes: both are plural of index) use .indices
- To get number, count the 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:例程索引在index 和 rindex.所以阅读好文档,好好阅读它 ;-)
PS: Routine indices is described just after index and rindex. So read the good doc, and read it well ;-)
链接:
这篇关于检查字符串是否包含子字符串.此外,获取匹配的索引和数量(乐)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文