rsearchindex(string, substring, [start])

Similar to rsearch, but return only the start index at which the substring is found, or 0 if it is not.


  1. Find the start index of a substring in a string:

    julia> rsearchindex("Hello, world!", "world")

    This example searches for the substring "world" within the string "Hello, world!" and returns the start index of the substring.

  2. Handle cases where the substring is not found:

    julia> rsearchindex("Hello, world!", "universe")

    If the substring is not found within the string, the function returns 0.

  3. Specify a starting position for the search:
    julia> rsearchindex("Julia programming language", "ia", 10)

    By providing a third argument, the function starts searching for the substring from the specified index (in this case, index 10).

Common mistake example:

julia> rsearchindex("Hello, world!", "Hello", 7)
ERROR: ArgumentError: invalid range: 7:5

In this example, an invalid range is specified for the starting position. The start index should always be less than or equal to the length of the string. Ensure that the start index is within the valid range before using rsearchindex.

See Also

find, findfirst, findin, findlast, findmin, findn, findnext, findnz, findprev, rsearch, rsearchindex, searchsorted, searchsortedfirst, searchsortedlast, sort, sort!, sortcols, sortperm, sortperm!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: