Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

strfind

Find Substrings


Description

Find substrings within strings of a character vector.

Usage

strfind(s1, s2, overlap = TRUE)
strfindi(s1, s2, overlap = TRUE)

findstr(s1, s2, overlap = TRUE)

Arguments

s1

character string or character vector

s2

character string (character vector of length 1)

overlap

logical (are overlapping substrings allowed)

Details

strfind finds positions of substrings within s1 that match exactly with s2, and is case sensitive; no regular patterns.

strfindi does not distinguish between lower and upper case.

findstr should only be used as internal function, in Matlab it is deprecated. It searches for the shorter string within the longer one.

Value

Returns a vector of indices, or a list of such index vectors if s2 is a character vector of length greater than 1.

See Also

Examples

S <- c("", "ab", "aba", "aba aba", "abababa")
s <- "aba"
strfind(S, s)
strfindi(toupper(S), s)
strfind(S, s, overlap = FALSE)

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.