Skip to content

Add string.strip_prefix and string.strip_suffix #743

Open
@BrewingWeasel

Description

@BrewingWeasel

These functions would return an Ok value with the prefix or suffix stripped, or an Error(Nil) value when the prefix or suffix does not exist in the string.

case string.strip_prefix("https://gleam.run", "https://") {
  Ok(site) -> "found site " <> site
  Error(Nil) -> "no site found" 
}
// -> "found site gleam.run"

(I know this can be done with adding strings in pattern matching, but this would be useful in pipes and there is no way to handle strip_suffix with that approach)

You can already achieve this through combining string.starts_with and string.drop_start, but that's rather clunky and this feels much more gleam-y to me.

I find myself using them a decent amount when I write rust, and I noticed they're even used several times in the gleam compiler!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions