Splitter.SplitTextByRanges
SplitterReturns a splitter function that extracts substrings from text at specified {offset, length} ranges.
Syntax
Splitter.SplitTextByRanges(ranges as list, optional startAtEnd as nullable logical) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
ranges | list | Yes | A list of two-element lists {offset, length}, each specifying a zero-based start position and character count for a segment. |
startAtEnd | logical | No | When true, offsets are measured from the end of the string. Defaults to false. |
Return Value
function — A function that extracts substrings from text according to the list of {offset, length} pairs.
Remarks
Splitter.SplitTextByRanges returns a splitter function that extracts non-contiguous or overlapping portions of a text value based on {offset, length} pairs. Each range specifies where to start (zero-based offset) and how many characters to take.
Unlike Splitter.SplitTextByPositions (which splits at cut points) or Splitter.SplitTextByLengths (which takes consecutive segments), this function allows arbitrary, possibly non-adjacent ranges. Ranges may overlap or leave gaps between them.
This is useful when dealing with fixed-width formats where only specific columns are needed, or when fields are interspersed with padding characters that should be skipped.
Examples
Example 1: Extract two non-adjacent ranges
Splitter.SplitTextByRanges({{0, 3}, {5, 4}})("ABCDE12345")Result | |
|---|---|
| 1 | ABC,2345 |
Example 2: Extract named fields from a fixed-width record
let
record = "SMITH JOHN 1985",
splitter = Splitter.SplitTextByRanges({{0, 10}, {10, 10}, {20, 4}}),
parts = splitter(record)
in
partsThe final output — a list of the three extracted range segments from the fixed-width record.
Result | |
|---|---|
| 1 | SMITH ,JOHN ,1985 |
Example 3: Use with Table.SplitColumn
Table.SplitColumn(
#table({"Data"}, {{"ABCXYZ"}}),
"Data",
Splitter.SplitTextByRanges({{0, 3}, {3, 3}}),
{"Part1", "Part2"}
)Part1 | Part2 | |
|---|---|---|
| 1 | ABC | XYZ |