Skip to content

New function 'around()' to surround a substring with a string #422

@bbottema

Description

@bbottema

surround itself is limited, as I would like to add something arround a substring, not the entire string.

Example:

around("1234x6789", 5, '>>', '<<'); // -> "1234>>x<<6789"
around("1234x6789", 4, 6, '>>', '<<'); // -> "123>>4x6<<789"
around("This is an apple", 8, 10, '[', ']'); // -> "This is [an] apple"
around("This is an apple", 'apple', '[', ']'); // -> "This is an [apple]"
around("This is pretty awesome!", /pre(tt)y/, ':', ':'); // -> "This is pre:tt:y awesome!"

Or something along these lines...

Right now I can only do it by manually doing 2 slices or splices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions