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.

two problems

Help for those learning Tcl or writing their own scripts.
Post Reply
k
keeper2
Voice
Posts: 12
Joined: Wed Jul 19, 2006 10:16 am

two problems

Post by keeper2 »

OK I am new to TCL scripting, I come from the mirc scripting camp ;).

I already read some articles about scripting in TCL, but don't find a answer to these two questions.

1. Is there a command like gettok in TCL so you can cut a string lets say:
This-is-a-test

into

This
is
a
test

and access all of these strings seperatly

2. I have a Textfile in which in each line a nickname is. Now I want to search the Textfile for a nick and if it is found that the TCL script do sth.
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

1. use [split "This-is-a-test" -]
2. http://tclhelp.net/#faqfile
k
keeper2
Voice
Posts: 12
Joined: Wed Jul 19, 2006 10:16 am

Post by keeper2 »

krimson wrote:1. use [split "This-is-a-test" -]
2. http://tclhelp.net/#faqfile
Thanks, but when I have the whole Textfile in data how to search for a specified string?
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

you can use something like this

Code: Select all

set openfile [open "path/to/your/file" r]
set data [read $openfile]

foreach line [split $data \n] {
  if {$line == nick1} { 
    #perform whatever commands
  } elseif {$line == nick2} {
    #perform other commands
  } else {
    #another set of commands
  }
}
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

don't forget to close the file.

Code: Select all

set openfile [open "path/to/your/file" r]
set data [read $openfile]
close $openfile

foreach line [split $data \n] {
  if {$line == nick1} {
    #perform whatever commands
  } elseif {$line == nick2} {
    #perform other commands
  } else {
    #another set of commands
  }
}
Post Reply