-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: strings, bytes: CutLast #71151
Comments
Related Issues
Related Code Changes (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
My last cut returns Also, mine is called |
Related: I also wanted (and implemented for my use case) a variant of
|
Not sure about that, i think that i would still prefer the fileName, ext, ok := strings.CutLast("test", ".")
fileName, ext, ok = strings.CutLast("test.test", ".") I know that this is a bad example, this should use |
Like with |
I like An argument against doing this is that it's trivial and clutters the already large docs (I sometimes wish we could group functions in the docs, so e.g. all the |
Here is one of my uses of metadata.URLSlug = strings.TrimRight(metadata.URLSlug, "/")
_, metadata.URLSlug, _ = stringx.LastCut(metadata.URLSlug, "/") In this case, I could probably have just used We could have a compromise position and in the false case it could do |
Proposal Details
A couple of times now while chopping up some strings I've happily enjoyed
strings.Cut
but had to write my ownCutLast
(the latest was implementing a subset of thepackage-url
spec where some of the things you need to find from the back of the string, and some from the front). It's a silly thing but it feels like an oversight.For reference, here is one of the
CutLast
I've implemented, verbatim. Trivial and obvious:The text was updated successfully, but these errors were encountered: