R/endswith.R

Defines functions strs_endswith

Documented in strs_endswith

#' Check if string ends with a specified suffix
#'
#' `strs_endswith` determines whether each element of a character vector ends
#' with a specified suffix. This function is similar to Python's
#' `str.endswith()` method.
#'
#' @param string A character vector where each element is a string to be
#' checked.
#' @param suffix The suffix to check for at the end of each element of `string`.
#' @return A logical vector of the same length as `string`, with each element
#' indicating whether the corresponding element of `string` ends with `suffix`.
#' @examples
#' strs_endswith("hello world", "world")
#' strs_endswith(c("test", "hello", "world"), "ld")
#' @export
#' @seealso [Python str.endswith() documentation](https://docs.python.org/3/library/stdtypes.html#str.endswith)
strs_endswith <- function(string, suffix) {
  stringi::stri_endswith_fixed(string, suffix)
}

Try the strs package in your browser

Any scripts or data that you put into this service are public.

strs documentation built on Sept. 11, 2024, 6:44 p.m.