Skip to content

Add methods to remove specified leading/trailing parts of a string #60796

Open
@Reprevise

Description

@Reprevise

Dart should have methods that are able to remove specified leading and trailing parts of a string. I propose using strip and it's associates, stripLeft and stripRight to keep in line with trim.

"@bar".stripLeft('@'); // "bar"
"bar@".stripRight('@'); // "bar"
"@bar@".strip('@'); // "bar"

"@@bar".stripLeft('@'); // "bar"
"@@bar".stripLeft('@@'); // "bar"
"@@bar".stripLeft('@@@'); // "@@bar"
"@@@bar".stripLeft('@@'); // "@bar"

The signature for the methods would be:

String strip(String pattern) {} // Only String, see lrhn's comment about matching backwards with RegEx

String stripLeft(Pattern pattern) {}

String stripRight(String string) {} // Only String, see lrhn's comment about matching backwards with RegEx

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-coretype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions