-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Replace at start / end of string #39192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can't you use |
@nicolas-grekas thank you for your response!
I don't think so (not sure I understand these methods with their edge cases correctly?) To stay in my example: However, in case the So iiuc I would need to do this: $prefix = $path->startsWith($basePath) ? "." : "";
$path = $path->after($basePath)->prepend($prefix); Which is arguably even less readable? |
Thank you for this suggestion. |
I would still like to see it, as I find the proposed solution highly confusing. |
Thank you for this suggestion. |
@carsonbot unchanged, yes. 😊 |
Solved by #43481: use this: u('file-image-0001.png')->trimPrefix('file-')->prepend('file-'); |
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
but that is a common enough task to warrant a separate function for, imo.
Example
(names tbd)
The text was updated successfully, but these errors were encountered: