| View previous topic :: View next topic |
| Author |
Message |
Pad Voice
Joined: 20 May 2011 Posts: 3
|
Posted: Fri May 20, 2011 4:14 pm Post subject: mysqltcl: replace string [Solved] |
|
|
Hi. I have an Eggdrop connecting to a MySQL database using mysqltcl and displaying the info on an IRC channel. Some rows contain text that I don't want to display like <br> and I want to omit it.
I tried to use the "string map" function ( http://wiki.tcl.tk/2819 ) but the bot crashed when it read the <br> on string map {<br> } $post. Then I tried to put only br to see if I was using it correctly but it seemed that the instruction was ignored.
I'm using this code to experiment:
| Code: |
mysqlmap $db_handle {id username post date} {
string map {br |} $post
putserv "privmsg $chan :$post"
}
|
But it display the text normally. What am I doing wrong?
Last edited by Pad on Sat May 21, 2011 4:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Fri May 20, 2011 6:03 pm Post subject: Re: mysqltcl: replace string |
|
|
| Code: | mysqlmap $db_handle {id username post date} {
set post [string map [list "<br>" " | "] $post]
putserv "privmsg $chan :$post"
} |
You use the string map to convert, but are never storing those results as a variable. I included the "set post" and bracket encapsulation [ ] around the [string map] to properly build the correct sequence of commands (stacking). I've also used [list "replace-this" "with-this"] which will work properly regarding variables replacements and special characters (ie, un-exploitable via errors or otherwise), as [list] is the preferred way to do [string map] rather than hand-crafting within curly braces { }.
School is now in session. The bell has rang. Classroom is filling with students. Grab a seat while you can...
/me takes a bite of the apple on his desk.
Having fun, is of tantamount importance as the task at hand. Remember this. Don't get angry, or give up when learning tcl. Have fun. Consider your failures as lessons, character building exercises. Not as some fundamental skill you lackl. Nobody is perfect. Having a laugh at stupid mistakes helps. Having fun while coding seriously is why I have a lot of success. For no other reason. I enjoy scripting for eggdrop. This is what keeps me sane. This is my wooden ship in a bottle, that I slowly build meticulously piece by piece over time. _________________ speechles' eggdrop tcl archive
Last edited by speechles on Fri May 20, 2011 6:22 pm; edited 1 time in total |
|
| Back to top |
|
 |
Pad Voice
Joined: 20 May 2011 Posts: 3
|
Posted: Fri May 20, 2011 6:21 pm Post subject: Re: mysqltcl: replace string |
|
|
It worked! Thank you!
One more thing: is there any special character in IRC to make a newline like '\n' for PHP, C, etc? |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Fri May 20, 2011 6:25 pm Post subject: |
|
|
| Code: | mysqlmap $db_handle {id username post date} {
set post [string map [list "<br>" "\n"] $post]
foreach line [split $post "\n"] {
putserv "privmsg $chan :$line"
}
} |
This will show you how to encapsulate and render newlines. Try this one too..  _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Pad Voice
Joined: 20 May 2011 Posts: 3
|
Posted: Fri May 20, 2011 6:35 pm Post subject: |
|
|
It worked too! Thank you very much!  |
|
| Back to top |
|
 |
|