mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
31 lines
709 B
Markdown
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"}
|
|
```
|
|
|
|
|