Radar · Go · Archive · Week 16 · Apr 13 – 19, 2026
strings, bytes: add CutLast
Nice to knowstdlib
- What changed
- The standard library now includes
strings.CutLastandbytes.CutLast, which split a string or byte slice around the last instance of a separator. - Production impact
- The source does not say.
- Try it
before, after, ok := strings.CutLast("a.b.c", ".").- Source
- github.com/golang/go/issues/71151
Understand it, then run it
The standard library now has a function called strings.CutLast. It works like the existing strings.Cut, but it splits a string at the last occurrence of a separator instead of the first. If the separator is not found, it returns the whole string, an empty string, and false. The same idea exists for bytes.CutLast. This makes it easier to split URLs or file paths from the end without writing your own helper.
Run it now
// This program demonstrates the new strings.CutLast function.
// It splits the string from the last slash, showing the path
// before the slash, the part after it, and whether the slash
// was found. The code runs with Go 1.27.1 and uses only the
// standard library.
package main
import (
"fmt"
"strings"
)
func main() {
s := "https://example.com/path/to/resource"
before, after, found := strings.CutLast(s, "/")
fmt.Printf("Original: %q\n", s)
fmt.Printf("Before: %q\n", before)
fmt.Printf("After: %q\n", after)
fmt.Printf("Found: %v\n", found)
}
What it printed when we ran it on Go 1.27.1
Original: "https://example.com/path/to/resource" Before: "https://example.com/path/to" After: "resource" Found: true
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed