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

<html><br/></html>


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: by 127.0.0.1
 
 
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0