I have a txtfile with on each line a few words like:
BLUB BLUB ONE TWO
BLUB OTHER WORDS
..
there are a few of these lines.. every odd line contains 2x BLUB (or another word twice), every even line 1x BLUB (or again another word).
I'm trying to make an mirc trigger that will rename BLUB BLUB into for example BLUB2 BLUB2
the trigger and the amount of arguments with the trigger is not a problem..
the problem is with lists and strings.
I can find the word BLUB in the lines but when I use lreplace to replace the words, the entire string becomes {BLUB2 BLUB2 ONE TWO}
<- adds those brackets..
when I use lappend it becomes BLUB2 BLUB2 {ONE TWO}
I'll pase a piece of the code here:
Code: Select all
if {[lindex $list1 0] == "sname" } {
set fs [open blub.txt r+]
set found 0
while {![eof $fs]} {
set newstring ""
gets $fs line
set list2 [split $line]
if { "[lindex $list2 0]" == "[lindex $list1 1]" } {
incr found
if { $found == "1" } {
lappend newstring [lindex $list1 2]
lappend newstring [lindex $list1 2]
lappend newstring [lrange $list2 2 [expr [llength $list2] -1] ]
putserv "PRIVMSG $chan :$newstring"
}
if { $found == "2" } {
lappend newstring [lreplace $list2 0 0 [lindex $list1 2]]
#putserv "PRIVMSG $chan :[lreplace $list2 0 0 [lindex $list1 2]]"
}
$list2 contains a list of the words in the line that was read from the textfile.
I compare the word BLUB from the trigger with the first word from each line in the textfile ( if { "[lindex $list2 0]" == "[lindex $list1 1]" } { )
lindex $list2 0 = that first word..
since there are only two lines with that BLUB on it I used $found here with 0 as start value and 1, 2 for when it is found.. cuz the first time it needs to to two replacements, the second time only one.
the three lappend's for when $found == "1" could also be written as:
Code: Select all
lreplace $list2 [lindex $list2 0] [lindex $list1 1]
lreplace $list2 [lindex $list2 1] [lindex $list1 1]
with lreplace {BLUB2 BLUB2 ONE TWO}
NOW, I wanna get rid of these annoying brackets {}

I have to mention that I'm a total n00b with tcl.. just started today, but have learned a lot already today and it's cool:)
thx in advance to anyone who can and is willing to help me out
greetz
Slashem