Skip to contents

strs_contains checks whether each element of a character vector contains a specified substring. This function mirrors the functionality of Python's str.__contains__() method.

Usage

strs_contains(string, substring)

Arguments

string

A character vector where each element is a string to be checked.

substring

The substring to search for within each element of string.

Value

A logical vector of the same length as string, with each element indicating whether the corresponding element of string contains substring.

Examples

strs_contains("hello world", "world")
#> [1] TRUE
strs_contains(c("apple", "banana", "cherry"), "a")
#> [1]  TRUE  TRUE FALSE