Skip to contents

Returns a vector of the indices where a string occurs in another string

Usage

indexOf(a, b, ignore.case = FALSE)

Arguments

a

string to be checked against

b

string to check

ignore.case

logical; if TRUE, case is ignored when performing the check

Value

Indices where b occurs in a. Returns NA if there are no occurences.

Details

If b is longer than a, indexOf returns NA, since it is not possible for a longer string to occur in a shorter string.

Author

Samuel Leung

Examples

indexOf("derek", "e")
#> [1] 2 4
indexOf("Animals", "a")
#> [1] 5
indexOf("Animals", "A")
#> [1] 1
indexOf("Animals", "a", ignore.case = TRUE)
#> [1] 1 5