DescTools (version 0.99.13)

StrPos: Find Position of First Occurrence Of a String

Description

This function finds the first occurrence of a substring within an object string.

Usage

StrPos(x, pattern, pos = 1, ...)

Arguments

x
a character vector in which to search for the pattern, or an object which can be coerced by as.character to a character vector.
pattern
character string (search string) containing the pattern to be matched in the given character vector. This can be a character string or a regular expression.
pos
pos allows, to define the start position for the search within x. The result will then be relativ to the begin of the truncated string. pos will be recycled.
...
the dots are passed to the function regexpr.

Value

  • a vector of the first position of pattern in x

Details

Returns the numeric position of the first occurrence of needle in the haystack string. If the search string is not found, the result will be NA. This is just a wrapper for the function regexpr.

See Also

StrChop, regexpr

Examples

Run this code
StrPos("t", levels(d.pizza$driver))

Run the code above in your browser using DataCamp Workspace