is.substring: Check if string x is a substring of y

Description Usage Arguments Value Examples

View source: R/miscutils.R

Description

check if a character string x is contained within another character string y. If the 'start' condition is set, only check if y starts with x (i.e. for partial match evaluations). The %substr% operator works equivalently, returning true if the lhs is a substring of the rhs.

Usage

1
2
3
is.substring(x, y, start = FALSE)

lhs %substr% rhs

Arguments

x

character - a single character string

y

character - a single character string that may contain x

start

logical - if TRUE only check the first subsequence of y for x

Value

logical - whether x is a substring of y

Examples

1
2
3
4
5
is.substring('abc', 'abcdef', start = TRUE) # TRUE
is.substring(' abc', 'abcdef', start = TRUE) # FALSE
is.substring('xyz', 'abcdef') # FALSE
is.substring('xyz','uvwxyz') # TRUE
'abc' %substr% '_abcdef_' # TRUE

duncankmckinnon/OKdplyr documentation built on Nov. 30, 2020, 1:13 a.m.