Perl6 是否有检查子字符串匹配的方法?
Does Perl6 have a method for checking substring matches?
如何在 Perl 中检查子字符串匹配?
index
方法returns和Int
:
"abc".index("b")
1
使用defined
,结果可以变成Bool
:
"abc".index("b").defined
True
这是惯用的方法还是有另一种方法 returns a Bool
?
方法是.contains
.
say 'abc'.contains('b'); # True
还有.starts-with
and .ends-with
.
say 'abc'.starts-with('c'); # False
say 'abc'.starts-with('a'); # True
say 'abc.txt'.ends-with('.txt') # True
您可以查看 Str 文档了解更多方法。
如何在 Perl 中检查子字符串匹配?
index
方法returns和Int
:
"abc".index("b")
1
使用defined
,结果可以变成Bool
:
"abc".index("b").defined
True
这是惯用的方法还是有另一种方法 returns a Bool
?
方法是.contains
.
say 'abc'.contains('b'); # True
还有.starts-with
and .ends-with
.
say 'abc'.starts-with('c'); # False
say 'abc'.starts-with('a'); # True
say 'abc.txt'.ends-with('.txt') # True
您可以查看 Str 文档了解更多方法。