Getting started with Tcl: example 9

This page is part of the Airplug documentation related to Tcl/Tk.
Back to the Tcl/Tk documentation page / Back to the Airplug documentation page

Lists versus strings

Script

#!/usr/bin/tclsh
# lits versus strings
 
puts stdout ""
 
set MyString "Happy New Year"
set MyList [list {a b} c hello 5]

# From a string to a list: split
foreach item [split $MyString] {
    puts stdout "item = $item"
}
 
puts stdout ""

# From a list to a string: join
# NB: concat applies on the list obtained with split $MyString
set MyString [join [concat [split $MyString] $MyList] : ]
puts stdout "Now, MyString = $MyString"

Output

item = Happy
item = New
item = Year
 
Now, MyString = Happy:New:Year:a b:c:hello:5

<br/>


This page is part of the Airplug documentation related to Tcl/Tk.
Back to the Tcl/Tk documentation page / Back to the Airplug documentation page

 
Back to top
en/doc/pub/tcltk/example-09.txt · Last modified: 2017/04/05 16:12 (external edit)
 
 
Driven by DokuWiki