-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: strings: add ReplaceBetween function #45003
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
Why does this belong in the standard library? See https://golang.org/doc/faq#x_in_std. |
The criteria is super vague and it seems to really depend on what side of the bed 3 key Go people wake up on in the morning, so I don't know how to answer it.
|
A key argument for something like this is not "it's useful"--everything that is proposed is useful, nobody proposes anything useless--but rather "here are several examples of existing real code that would benefit from this." Thanks. |
Why can this not just be done with regular expressions? |
regex:
|
I think regular expressions makes way more sense as a general case for this. If that's not fast enough for your specific use case, implement it manually. This seems extremely specific for something to be included in the standard library. |
In terms of existing examples, quickly and efficiently converting all html tags come to mind:
My actual use-case is merely to remove all content between a start and different end token. This proposal is more general to be more useful. |
This comment has been minimized.
This comment has been minimized.
Actually I think I misunderstood. The OP's request should be easily doable using just strings.Replace. This does not even really fit my use-case for string interpolation. |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
ReplaceBetween(s, start, end, replace string, n int) string
ReplaceBetween will find all (non-overlapping) substrings beginning with
start
(token) and ending withend
and replace all characters in-between (inclusive ofstart
andend
) withreplace
string.The text was updated successfully, but these errors were encountered: