Splitter.SplitTextByEachDelimiter
Makes a function that cuts text once at each separator of a list, in the order the list gives them.
Group: Splitters, combiners, replacers and comparers. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Splitter.SplitTextByEachDelimiter(delimiters as list, optional quoteStyle as nullable number, optional startAtEnd as nullable logical) as function
| Parameter | Type | Description |
|---|---|---|
delimiters | list | The separators, each a text, used one after the other, each once. |
quoteStyle | nullable number optional | QuoteStyle.Csv (the default): a delimiter inside double quotes does not split, and the quotes are taken off; QuoteStyle.None: quotes are ordinary characters. |
startAtEnd | nullable logical optional | true to work from the end of the text toward its start. |
Returns
function. A splitter: given a text, a piece before each separator and the rest after the last one.
Remarks
- A splitter is a function of one text that gives a list of texts.
Table.SplitColumnandTable.FromListtake one; you can also call it yourself, as the examples do. - Each separator splits once only: what follows the last one stays whole, separators and all.
- With startAtEnd the separators are looked for from the end: the first of the list splits off the last piece.
- Quotes count by default: a separator between double quotes is part of the piece. Pass
QuoteStyle.Nonewhen quotes are just characters in the data.
Examples
A country, a postcode and the rest
Splitter.SplitTextByEachDelimiter({"-", "/"})("NO-0150/Oslo-Sentrum")
{"NO", "0150", "Oslo-Sentrum"}
The second dash, in Oslo-Sentrum, is not a separator any more.
The first name and the rest
Splitter.SplitTextByEachDelimiter({" "})("Kari Hansen Nordmann")
{"Kari", "Hansen Nordmann"}
The last name and the rest
Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.None, true)("Kari Hansen Nordmann")
{"Kari Hansen", "Nordmann"}
Related functions
Splitter.SplitTextByDelimiter, Splitter.SplitTextByAnyDelimiter, Table.SplitColumn.