Skip to content

[String] Replace at start / end of string #39192

@apfelbox

Description

@apfelbox

Description

Hi, I would be great to have a method to replace strings only at the start/end of the string.

This is currently possible with

if ($path->startsWith($basePath))
{
    $path = $path->slice($basePath->length())->prepend("...");
}

but that is a common enough task to warrant a separate function for, imo.

Example

$baseDir = __DIR__;
$possiblyRelative = $path->replaceStart($baseDir, ".");

(names tbd)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions