Splitter.SplitTextByPositions
SplitterReturns a splitter function that divides text at the specified zero-based character positions.
Syntax
Splitter.SplitTextByPositions(positions as list, optional startAtEnd as nullable logical) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
positions | list | Yes | A list of zero-based character positions at which to split the text. The first position is typically 0 to include the text from the start. |
startAtEnd | logical | No | When true, positions are counted from the end of the string. Defaults to false. |
Return Value
function — A function that splits text at each specified character position.
Remarks
Splitter.SplitTextByPositions returns a splitter function that, when applied to a text value, slices the text at each position in the positions list. Each position defines the start of the next segment.
The positions list should be in ascending order. Typically the first element is 0 to start from the beginning of the string. Each subsequent position marks where the next segment begins. Text between consecutive positions forms one segment.
This is useful for parsing fixed-width formats where you know the column start positions rather than the lengths.
Note the difference from Splitter.SplitTextByRanges: positions defines cut points, while ranges specifies {offset, length} pairs.
Examples
Example 1: Split at positions 0, 2, and 5
Splitter.SplitTextByPositions({0, 2, 5})("ABCDEFGH")Result | |
|---|---|
| 1 | AB,CDE,FGH |
Example 2: Parse a fixed-width record with known column starts
let
record = "JohnDoe 30M",
splitter = Splitter.SplitTextByPositions({0, 8, 10}),
parts = splitter(record)
in
partsThe final output — a list of the three positional segments extracted from the fixed-width record.
Result | |
|---|---|
| 1 | JohnDoe ,30,M |
Example 3: Use with Table.SplitColumn
Table.SplitColumn(
#table({"Record"}, {{"NY10001"}}),
"Record",
Splitter.SplitTextByPositions({0, 2}),
{"State", "ZipCode"}
)State | ZipCode | |
|---|---|---|
| 1 | NY | 10001 |