DOKK / manpages / debian 12 / tcl8.6-doc / join.3tcl.en
join(3tcl) Tcl Built-In Commands join(3tcl)


join - Create a string by joining together list elements

join list ?joinString?


The list argument must be a valid Tcl list. This command returns the string formed by joining all of the elements of list together with joinString separating each adjacent pair of elements. The joinString argument defaults to a space character.

Making a comma-separated list:

set data {1 2 3 4 5}
join $data ", "

→ 1, 2, 3, 4, 5

Using join to flatten a list by a single level:

set data {1 {2 3} 4 {5 {6 7} 8}}
join $data

→ 1 2 3 4 5 {6 7} 8

list(3tcl), lappend(3tcl), split(3tcl)

element, join, list, separator

Tcl