| View previous topic :: View next topic |
| Author |
Message |
keeper2 Voice
Joined: 19 Jul 2006 Posts: 12
|
Posted: Wed Jul 19, 2006 10:25 am Post subject: two problems |
|
|
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. |
|
| Back to top |
|
 |
krimson Halfop

Joined: 19 Apr 2006 Posts: 86
|
|
| Back to top |
|
 |
keeper2 Voice
Joined: 19 Jul 2006 Posts: 12
|
Posted: Wed Jul 19, 2006 10:35 am Post subject: |
|
|
Thanks, but when I have the whole Textfile in data how to search for a specified string? |
|
| Back to top |
|
 |
krimson Halfop

Joined: 19 Apr 2006 Posts: 86
|
Posted: Wed Jul 19, 2006 11:21 am Post subject: |
|
|
you can use something like this
| Code: | 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
}
} |
|
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Thu Jul 20, 2006 1:18 am Post subject: |
|
|
don't forget to close the file.
| Code: | 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
}
} |
|
|
| Back to top |
|
 |
|