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.

delimiter or split :P

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

delimiter or split :P

Post by ultralord »

hello.. i have one variable $nicks and inside i set some nicks like "nick1 nick2 nick3 nick4 nick5" is it possible to split the variable and set the nick1 like $nick1 = nick1 (from previus variable after split) $nick2 = nick2 ... up to nick5 just want to split the 1st variable to 5 like nicks..


thanks
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set nicks "nick1 nick2 nick3 nick4 nick5"

#use this if there could be more than 5 nicks in $nicks
for {set i 0} {$i < 6} {incr i} { 
	set nick[expr $i + 1] [lindex [split $nicks] $i]
}

#or you could use this if it conatins max 5 nicks
foreach {nick1 nick2 nick3 nick4 nick5} [split $nicks ]  {}
Elen sila lúmenn' omentielvo
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

thnx a lot i am going to try it
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

foreach item [split $nicks] {
set nick[expr {[lsearch [split $nicks] $item] + 1}] $item
}
Post Reply