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.
Old posts that have not been replied to for several years.
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Thu Oct 30, 2003 11:10 am
Hi,
I got a problem with lreplace and lsearch
. I tried a few ways but I don't get it working correctly!
I got his:
msg = Hello Guys. Blablabla bla bla IRC bla bla bla bla.
I want to replace in $msg that IRC with $nick (current nick of the triggerer).
So I tried this one:
set msg [lreplace $msg [lsearch $msg "IRC"] [lsearch $msg "IRC"] $nick]
But then he put's $nick in FRONT of the line instead of replacing IRC with $nick
.
Can someone help me please?
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Thu Oct 30, 2003 11:29 am
My guess is that the element "IRC" is not found, so 'lsearch' returns "-1" and that's where your nick ends up
(remember: it's case sensitive)
Also make sure your $msg is a list before using list commands on it
and then
if you want it output as a string later on.
Have you ever read "The Manual"?
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Thu Oct 30, 2003 11:37 am
Hi,
thanks for your answer.
set msg [split $msg]
set msg [lreplace $msg [lsearch $msg "IRC"] [lsearch $msg "IRC"] $nick]
set msg [join $msg]
I tried this code now but it's still the same. IRC is still not beeing replaced and my irc-nick lands in front of $msg
.
Any other idea??
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Thu Oct 30, 2003 11:45 am
BiLL wrote: IRC is still not beeing replaced and my irc-nick lands in front of $msg
.
Check if the element is found before you do the replacement (like my lsearch of [channels] in our
previous thread )
'lsearch' returns -1 when what you search for is not found in the list and that's the only thing that could cause this behaviour. Again: check the case of that word in your list.. are you sure it's in all uppercase like the element you search for?
Have you ever read "The Manual"?
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Thu Oct 30, 2003 12:13 pm
Ah, I found the bug
Hehe.
Its because I am using that msg:
greetings, please query NICK, this is my msg.
Its because I am using NICK, <- if i leave the , it works. With , it doenst work. You maybe can help me with that also? So I can replace NICK, with my IRCNICK, ? There should be a way!
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Thu Oct 30, 2003 4:53 pm
please someone help me i don't know how to fix that
GodOfSuicide
Master
Posts: 463 Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria
Post
by GodOfSuicide » Thu Oct 30, 2003 5:23 pm
BiLL wrote: Its because I am using NICK, <- if i leave the , it works. With , it doenst work. You maybe can help me with that also?
NICK is not NICK, in a list
here's a better proc (and no, it's not by me
)
Code: Select all
proc varrep {string what with} {
if {![string match "*$what*" $string]} {return $string}
set cutstart [expr [string first $what $string] - 1]
set cutstop [expr $cutstart + [string length $what] + 1]
set string [string range $string 0 $cutstart]$with[string range $string $cutstop end]
return $string
}
set msg [varrep $msg "nick" $::botnick]
BiLL
Halfop
Posts: 78 Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany
Post
by BiLL » Thu Oct 30, 2003 6:25 pm
great that works perfect thanks!