Summary#
Text.Join(separator, values) concatenates the elements of values into a single string, inserting
separator between each adjacent pair. It is the inverse of Text.Split, and identical to
string.Join(separator, values).
Signature#
Text.Join(<string> separator, <list> values) -> string
string.Join(<string> separator, <list> values) -> string // the same operationDescription#
The separator goes only between elements, never at the ends: joining ["a", "b", "c"] with ", " gives
"a, b, c" — two separators for three elements. Two consequences follow directly:
- an empty list joins to
""(no elements, so no separators); - a single-element list joins to just that element (nothing to put a separator between).
An empty separator simply concatenates: Text.Join("", ["a", "b"]) is "ab".
Text.Join and Text.Split are exact inverses when the separator does not itself appear inside an element:
splitting on ", " and re-joining on ", " returns the original string. Text.Join runs in memory — it
builds one string from a set of values already in hand.
Examples#
// Split a CSV line, drop the empties, and re-join with a cleaner separator.
string Reflow(string csv) {
return Text.Join(" · ", Text.Split(csv, ","));
}[Test]
void Text_join_answers() {
Assert.Equal("a · b · c", Reflow("a,b,c"));
// Round-trip: split then join on the same separator returns the original.
Assert.Equal("one, two, three", Text.Join(", ", Text.Split("one, two, three", ", ")));
// A single element gets no separator; an empty separator just concatenates.
Assert.Equal("solo", Text.Join(", ", Text.Split("solo", ",")));
Assert.Equal("ab", Text.Join("", Text.Split("a,b", ",")));
}See also#
- Text.Split — the inverse: string → list
- String interpolation & format specifiers —
$"{a}-{b}", the other way to build a string from values - Text.Length, Text.IsEmpty, Text.IsBlank, Text.Contains, Text.StartsWith, Text.EndsWith — asking questions about the resulting string