strs_contains: Check if string contains a substring

View source: R/contains.R

strs_containsR Documentation

Check if string contains a substring

Description

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")
strs_contains(c("apple", "banana", "cherry"), "a")

strs documentation built on Sept. 11, 2024, 6:44 p.m.