6

I need to know if there are any functions available in R that allow me to check if one string contains a substring and return a boolean. I've already tried str_detect but that doesn't suit my need.

For example:

string = 12345REFUND4567

and

substring = REFUND

contains(string,substring) would ideally return TRUE since 12345REFUND4567 contains REFUND.

contains(string,substring) is just the format I'd imagine the function to take.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Luca Foerster
  • 93
  • 1
  • 2
  • 4

1 Answers1

14

You probably are looking for grepl:

string <- "12345REFUND4567"
grepl("REFUND", string, fixed=TRUE)

[1] TRUE
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360