Taking your example, to get the second word from the string, you can use the follwing.
set word [lindex [split $testvar] 1]
OK, so the "set word you can undertsand.
The lindex command is used to get an item out of a list. You have to pass it the list, and the item number you want from the list. The split command is used to convert a string into a list (this is also required to make things safe for later). The 1 is the index within the list that you wish to get. Note the index is 1, but the word we want is word 2, this is because, like in most languages, the first eliment is 0.
K, Having a problem using it.... maybe you could clear it up, or will I HAVE to remove the { for this to work?
using a bind to
bind msg - test handletest
proc handletest { nick host hand args } {
#shows what the output is
putlog "hand [lindex [split $args] 0]"
if {[validuser [lindex [split $args] 0]]} {
puthelp "NOTICE $nick :your handle is ok"
}
return 0
}
/msg bot test HANDLE
works fine, problem is...
/msg bot test HANDLE <anything else here>
returns {handle - thus causing the error and not checking right, so have I got the syntax of the check wrong, or am I going to have to remove the { } brackets?
Don't use "args" as the name of your last argument in your procedure. It is a special tcl keyword that creates a list out of the remaining arguments, which adds the extra { and } that you are seeing.
Just rename it to "text" or something else, and it should be fine.