Files
lo/docs/data/core-cutprefix.md
T
2025-10-06 17:15:49 +02:00

36 lines
855 B
Markdown

---
name: CutPrefix
slug: cutprefix
sourceRef: slice.go#L800
category: core
subCategory: slice
playUrl: https://go.dev/play/p/7Plak4a1ICl
variantHelpers:
- core#slice#cutprefix
similarHelpers:
- core#slice#cutsuffix
- core#slice#cut
- core#slice#trimprefix
- core#slice#trimleft
- core#slice#slice
- core#slice#drop
- core#slice#hasprefix
position: 0
signatures:
- "func CutPrefix[T comparable, Slice ~[]T](collection Slice, separator Slice) (after Slice, found bool)"
---
Returns the collection without the provided leading prefix and a boolean indicating whether it was present.
```go
right, found := lo.CutPrefix([]string{"a", "b", "c", "d"}, []string{"a", "b", "c"})
// right: []string{"d"}
// found: true
right, found = lo.CutPrefix([]string{"a", "b", "c"}, []string{"b"})
// right: []string{"a", "b", "c"}
// found: false
```