Files
lo/docs/data/core-trimprefix.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

31 lines
709 B
Markdown

---
name: TrimPrefix
slug: trimprefix
sourceRef: slice.go#L858
category: core
subCategory: slice
playUrl: https://go.dev/play/p/8O2RoWYzi8J
variantHelpers:
- core#slice#trimprefix
similarHelpers:
- core#slice#trim
- core#slice#trimleft
- core#slice#trimright
- core#slice#trimsuffix
position: 0
signatures:
- "func TrimPrefix[T comparable, Slice ~[]T](collection Slice, prefix Slice) Slice"
---
Removes all leading occurrences of the given prefix from the collection.
```go
result := lo.TrimPrefix([]int{1, 2, 1, 2, 3, 1, 2, 4}, []int{1, 2})
// []int{3, 1, 2, 4}
result = lo.TrimPrefix([]string{"hello", "world", "hello", "test"}, []string{"hello"})
// []string{"world", "hello", "test"}
```