Joining list elements
While the concat
command is more than capable of merging lists and arguments into a single list, Tcl also provides the join
command to expand the functionality. The join
command will not only merge the arguments, but also allows insertion of a separation character into the returned string. Note that the variable provided must contain a list, set of lists, or standalone values. The syntax is as follows:
join list delimiter
How to do it…
In the following example, we will join the elements of a list and create a comma-delimited string. Return values from the commands are provided for clarity. Enter the following command:
% set input {John Mary Bill}
John Mary Bill
% join $input ", "
John, Mary, Bill
How it works…
The join
command ...
Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.