Skip to content

Strip suffix

Description

The suffix will be removed from the string exactly once, if found.

Usage

<Expr>$str$strip_suffix(suffix = NULL)

Arguments

suffix The suffix to be removed.

Details

This method strips the exact character sequence provided in suffix from the end of the input. To strip a set of characters in any order, use $strip_chars_end() instead.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = c("foobar", "foobarbar", "foo", "bar"))
df$with_columns(
  stripped = pl$col("a")$str$strip_suffix("bar")
)
#> shape: (4, 2)
#> ┌───────────┬──────────┐
#> │ a         ┆ stripped │
#> │ ---       ┆ ---      │
#> │ str       ┆ str      │
#> ╞═══════════╪══════════╡
#> │ foobar    ┆ foo      │
#> │ foobarbar ┆ foobar   │
#> │ foo       ┆ foo      │
#> │ bar       ┆          │
#> └───────────┴──────────┘