On 2/2/19 6:21 AM, Brad Gilbert wrote:
`.index` is going to be the fastest because it is directly using NQP
ops which are built into the VM.

     'abcdefg'.index('de'); # 3

If you want all of the indexes, use `.indices`

     'abcdefabc'.indices('abc'); # 0, 6

`.index` will return `Nil` if it doesn't find anything, and `.indices`
will return an empty list.

     'abc'.index('ZZ'); # Nil
     'abc'.indices('ZZ'); # ()

To see the actual code implementing these (and other similar methods):

- .index: 
https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm6#L255-L284
- .indices: 
https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm6#L206-L252
- .contains: 
https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm6#L183-L203
- .rindex: 
https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm6#L294-L323

On Sat, Feb 2, 2019 at 5:13 AM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:

Hi All,

What is the fastest way to find the index of
a sub string in a string?

-T

Thank you!

Reply via email to