Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)

I'm trying to determine if a string is a subset of another string. For example:

chars <- "test"
value <- "es"
I want to return TRUE if "value" appears as part of the string "chars". In the following scenario, I would want to return false:
chars <- "test"
value <- "et"

1 Answer

0 votes
by

You can use grepl() function that returns TRUE if a string contains the pattern, and otherwise returns FALSE.

Basic syntax for grepl() function is given below:

grepl(pattern, x, ignore.case = FALSE, perl = FALSE,

  fixed = FALSE, useBytes = FALSE)

 

In your case:

chars <- "test"

value <- "es"

grepl(value, chars)

[1] TRUE

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...