-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add string.RemovePrefix/RemoveSuffix (dupe) #27414
Comments
Why did we split it off the original issue #14386? |
[Edited] Because of the ask for a formal proposal. My understanding of the "example of a good proposal" was that the formal spec should be in the preamble, and not require scrolling through discussion. I can inline it here if that's preferable for easier tracking? |
It's unfortunate this allocates a temporary string: Since this original issue was discussed, |
Can't we just update the original proposal? now we have 2 issues tracking the same thing. |
I just added |
OK, updated original issue: https://github.com/dotnet/corefx/issues/1244 |
[Picking up an item from
up-for-grabs
]It is useful to have methods that trim a specified prefix or suffix from a string. This is somewhat simple for a developer to write themselves, but it seems to be a common enough request that it would be useful to support directly, especially in regards to robustness and performance.
Here are some references gleaned from the original issue.
http://stackoverflow.com/questions/7170909/trim-string-from-end-of-string-in-net-why-is-this-missing
http://stackoverflow.com/questions/4101539/c-sharp-removing-strings-from-end-of-string
http://stackoverflow.com/questions/5284591/how-to-remove-a-suffix-from-end-of-string
http://stackoverflow.com/questions/4335878/c-sharp-trimstart-with-string-parameter
Usage
There are only 2 overloads for each method, as shown in the following examples:
Background
Proposed API
Details, Decisions, Questions
Some of these items from @tarekgh's feedback: https://github.com/dotnet/corefx/issues/1244#issuecomment-261606399
namespace System
Decision: No
bool repeat
overloads. The callsite can call this recursively (at the risk of more allocations)."SIdId".RemoveSuffix("Id")
should return"SId"
, not"S"
.TrimEnd
andTrimStart
that have a non-repeating behavior because it's inconsistent with the existing ones.POC
This is a relatively simple addition, POC code below:
The text was updated successfully, but these errors were encountered: