如何检查 Perl 中的子字符串匹配?index
方法返回 Int
:
"abc".index("b")
1
使用
defined
,结果可以变成Bool
:"abc".index("b").defined
True
这是惯用的方式还是有另一种方法返回
Bool
?
最佳答案
方法是 .contains
.
say 'abc'.contains('b'); # True
还有 .starts-with
和 .ends-with
.say 'abc'.starts-with('c'); # False
say 'abc'.starts-with('a'); # True
say 'abc.txt'.ends-with('.txt') # True
你可以看看Str更多方法的文档。
关于string - Perl6 有检查子串匹配的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49592008/