Skip to content

stdlib feature request: trimSuffix/trimPrefix #1322

Description

@rowanmoul

I suspect that these are common enough needs that it would be nice to have them in the standard library.
Of course I know that I can already accomplish it with std.endsWith/std.startsWith, std.length and slice syntax:

local trimSuffix(str, suffix) =
  if std.endsWith(str, suffix) then
    str[0:std.length(str) - std.length(suffix)]
  else
    str;

I could also use std.strReplace if I was 100% sure the prefix/suffix would never exist anywhere else in the string.

I'm not sure what the goal of the standard library is. Perhaps you just want to provide the minimum set of building blocks for people to make their own methods like above. If the goal is instead to provide a suite of commonly used functions, these would be a great addition to it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions