mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
29 lines
592 B
Markdown
29 lines
592 B
Markdown
---
|
|
name: ChunkString
|
|
slug: chunkstring
|
|
sourceRef: string.go#L130
|
|
category: core
|
|
subCategory: string
|
|
playUrl: https://go.dev/play/p/__FLTuJVz54
|
|
variantHelpers:
|
|
- core#string#chunkstring
|
|
similarHelpers:
|
|
- core#slice#chunk
|
|
- core#string#substring
|
|
- core#string#words
|
|
- core#string#runelength
|
|
- core#string#split
|
|
position: 20
|
|
signatures:
|
|
- "func ChunkString[T ~string](str T, size int) []T"
|
|
---
|
|
|
|
Splits a string into chunks of the given size. The last chunk may be shorter. Returns [""] for empty input.
|
|
|
|
```go
|
|
lo.ChunkString("1234567", 2)
|
|
// []string{"12", "34", "56", "7"}
|
|
```
|
|
|
|
|