gpt4 book ai didi

raku - 检查字符串是否包含子字符串。此外,获取匹配的索引和数量(乐)

转载 作者:行者123 更新时间:2023-12-03 14:07:41 24 4
gpt4 key购买 nike

FAQ:在 Raku 中,如何检查 String包含一个子串?在哪里和多少次?
我想要 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:例程 indexrindex很酷,但只能得到一场比赛。

相关链接:
  • Answer with Regex
  • Answer on List (Array)
  • Contiguous Sequences on List
  • Answer on Hash (Dictionary)
  • 最佳答案

  • 要检查它是否包含,请使用 .contains获得 Bool这是一个 cool 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:日常 indicesindex 之后描述和 rindex .因此,请阅读好文档,并好好阅读 ;-)
  • 链接:
  • contains in regex
  • 同样的问题在 Python , Perl
  • 关于raku - 检查字符串是否包含子字符串。此外,获取匹配的索引和数量(乐),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60853431/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com