This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
b
bisbis
Post
by bisbis » Wed Mar 17, 2004 11:57 am
Hello, im making a tcl script and need some help.
I want to create a variable(or array) like
set namenick "John|johnny:Peter|pete:Jack|ripper"
| is used to separate name from nick and : is used to separate different persons.
Now how can i output them like this:
John has the nickname is johnny
Peter has the nickname pete
..
Note: We do NOT know how many names/nicks in the variable is.
I used set array but it seemed slow and outputted them in a random order.
Thanks very much in advice!
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Wed Mar 17, 2004 4:23 pm
Use a list.
Code: Select all
set namenick {John johnny Peter pete Jack ripper "Firstname Lastname" theNick}
foreach {name nick} $namenick {
output "$name has the nickname $nick"
}
The last entry is just to show you how to add names with spaces in them. Your string could be turned into a list like this by splitting it on "|" and ":" (set demo [split $namenick "|:"])
Have you ever read "The Manual"?
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Thu Mar 18, 2004 12:20 pm
refer lappend if you want to add something the list and lreplace to edit in a general TCL help.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under
The MIT License
Love hurts, love strengthens...