Lines.ToText
LinesConverts a list of text lines into a single text value by joining the lines with line separators.
Syntax
Lines.ToText(lines as list, optional quoteStyle as nullable number, optional includeByteOrderMark as nullable logical) as textParameters
| Name | Type | Required | Description |
|---|---|---|---|
lines | list | Yes | A list of text values, each representing one line. |
quoteStyle | number | No | Controls how line endings within quoted fields are treated. Use QuoteStyle.None (default) or QuoteStyle.Csv. |
includeByteOrderMark | logical | No | When true, prepends a byte order mark to the output. Defaults to false. |
Return Value
text — A single text value with each element from lines joined by line feed characters.
Remarks
Lines.ToText joins a list of text values into a single multi-line string by inserting a line feed character (#(lf)) between each element. This is the inverse of Lines.FromText, making the two functions natural companions for round-trip text processing: split a text into lines, transform or filter them, then rejoin with Lines.ToText.
The function is most useful when you have manipulated a list of lines and need to produce a single text output — for example, after filtering out blank or comment lines from a source file, reordering lines, or applying transformations to each line.
Unlike Text.Combine, which requires you to explicitly provide a delimiter, Lines.ToText automatically uses the standard line separator. This makes intent clearer when the goal is to reconstruct line-oriented text. Use Text.Combine when you need a custom separator such as a comma or tab. For binary output (e.g., writing to a file or API), use Lines.ToBinary instead.
Examples
Example 1: Join a list of lines into multi-line text
Lines.ToText({"CustomerName,Product", "Alice,Widget A", "Bob,Gadget B"})Result | |
|---|---|
| 1 | CustomerName,Product Alice,Widget A Bob,Gadget B |
Example 2: Filter lines then rejoin
let
source = "Alice,Widget A#(lf)#(lf)Bob,Gadget B#(lf)#(lf)Charlie,Widget C",
lines = Lines.FromText(source),
nonEmpty = List.Select(lines, each _ <> ""),
result = Lines.ToText(nonEmpty)
in
resultThe final output — rejoins the non-empty lines into a clean multi-line text value.
Result | |
|---|---|
| 1 | Alice,Widget A Bob,Gadget B Charlie,Widget C |
Example 3: Reconstruct a modified text file
let
lines = {"Alice,Widget A", "Bob,Gadget B", "Charlie,Widget C"},
transformed = List.Transform(lines, each
Text.BeforeDelimiter(_, ",") & "," & Text.Upper(Text.AfterDelimiter(_, ","))
),
result = Lines.ToText(transformed)
in
resultThe final output — joins the transformed lines into a single multi-line text value.
Result | |
|---|---|
| 1 | Alice,WIDGET A Bob,GADGET B Charlie,WIDGET C |