From 11b596c22dcabf91f9595da778b00e26f4d661a8 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Thu, 9 Apr 2026 22:04:07 +0800 Subject: bytes,strings: add CutLast Fixes #71151 Change-Id: I3b3d49c35b0fa2c1220d3f39bbd506cc072b52b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/764601 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com Reviewed-by: David Chase Reviewed-by: Sean Liao Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer --- src/strings/strings.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/strings/strings.go') diff --git a/src/strings/strings.go b/src/strings/strings.go index 367e0a8e24..70297f1e69 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -1289,3 +1289,14 @@ func CutPrefix(s, prefix string) (after string, found bool) { func CutSuffix(s, suffix string) (before string, found bool) { return stringslite.CutSuffix(s, suffix) } + +// CutLast slices s around the last instance of sep, +// returning the text before and after sep. +// The found result reports whether sep appears in s. +// If sep does not appear in s, CutLast returns s, "", false. +func CutLast(s, sep string) (before, after string, found bool) { + if i := LastIndex(s, sep); i >= 0 { + return s[:i], s[i+len(sep):], true + } + return s, "", false +} -- cgit v1.3