To check if a string ends with a specific suffix in R, you can use the endsWith()
function.
In this example,
str1
with a string value of "Hello World"
.endsWith()
function with the string object str1
and the suffix "World"
.endsWith()
function returns TRUE
if the string ends with the specified suffix; otherwise, it returns FALSE
.str1 <- 'Hello World'
endsWithWorld <- endsWith(str1, 'World')
print(paste('String ends with suffix 'World':', endsWithWorld))
String ends with suffix 'World': TRUE
In this example,
str2
with a string value of "apple"
.endsWith()
function with the string object str2
and the suffix "banana"
.endsWith()
function returns TRUE
if the string ends with the specified suffix; otherwise, it returns FALSE
.str2 <- 'apple'
endsWithBanana <- endsWith(str2, 'banana')
print(paste('String ends with suffix 'banana':', endsWithBanana))
String ends with suffix 'banana': FALSE
In this tutorial, we learned How to Check if String ends with Specific Suffix in R language with well detailed examples.