Splitter.SplitTextByRepeatedLengths
SplitterReturns a splitter function that repeatedly splits off substrings of a fixed length from the text.
Syntax
Splitter.SplitTextByRepeatedLengths(length as number, optional startAtEnd as nullable logical) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
length | number | Yes | The fixed number of characters for each chunk. |
startAtEnd | logical | No | When true, chunks are taken from the end of the string first. Defaults to false. |
Return Value
function — A function that splits text into consecutive fixed-length chunks.
Remarks
Splitter.SplitTextByRepeatedLengths returns a splitter function that slices its input into consecutive chunks of the specified length. If the text length is not evenly divisible by length, the final chunk contains the remaining characters.
When startAtEnd is true, chunks are taken from the right side of the string first, so the potentially shorter partial chunk appears at the beginning of the result list.
This is useful for parsing packed binary-format text strings, segmenting hex data, chunking encoded strings, or splitting data into fixed-size page-width columns.
Examples
Example 1: Split into chunks of three characters
Splitter.SplitTextByRepeatedLengths(3)("ABCDEFGHI")Result
Result | |
|---|---|
| 1 | ABC,DEF,GHI |
Example 2: Remainder in the last chunk
Splitter.SplitTextByRepeatedLengths(4)("ABCDEFGHIJ")Result
Result | |
|---|---|
| 1 | ABCD,EFGH,IJ |
Example 3: Split from the end (remainder first)
Splitter.SplitTextByRepeatedLengths(4, true)("ABCDEFGHIJ")Result
Result | |
|---|---|
| 1 | AB,CDEF,GHIJ |
Example 4: Split a hex string into bytes
Splitter.SplitTextByRepeatedLengths(2)("48656C6C6F")Result
Result | |
|---|---|
| 1 | 48,65,6C,6C,6F |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks