In R, you can use the 'startsWith' function from the 'stringr' package to check if a string starts with a specific prefix.
In this example,
# R
library(stringr)
startsWithPrefix <- function(str, prefix) {
return(str_starts(str, prefix))
}
str <- "Hello World"
prefix <- "Hello"
startsWith <- startsWithPrefix(str, prefix)
print(paste("String starts with prefix '", prefix, "': ", startsWith))
[1] "String starts with prefix ' Hello ': TRUE"
In this tutorial, we learned How to Check if String starts with Specific Prefix in R language with well detailed examples.