| View previous topic :: View next topic |
| Author |
Message |
T-Xorcist Halfop
Joined: 14 Nov 2005 Posts: 47 Location: Netherlands
|
Posted: Thu Apr 13, 2006 4:54 pm Post subject: Remove # in front off channel. |
|
|
Hi all,
I want to execute an MySQL query with the channelname in the query, like join.php?chan=$chan.
All sounds pretty neat, but MySQL / PHP does not support the # sign.
My question is, how do I remove the # in front of the channel to execute the MySQL query:
Example
-----------
Bot is in #T-Xorcist
The query will be join.php?chan=#T-Xorcist
The query MUST be join.php?chan=T-Xorcist
Can anyone help me out with this issue?
Thanks in advance. _________________ is-1337.org IRC server! |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Thu Apr 13, 2006 5:31 pm Post subject: |
|
|
here is how to strip the # off:
| Code: | | regsub {#} $chan {} chan |
|
|
| Back to top |
|
 |
T-Xorcist Halfop
Joined: 14 Nov 2005 Posts: 47 Location: Netherlands
|
Posted: Thu Apr 13, 2006 5:52 pm Post subject: |
|
|
I got this solution JUST find out:
| Code: | | regsub -all "#" $chan "" channelname |
Bad, not safe or? _________________ is-1337.org IRC server! |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Thu Apr 13, 2006 6:58 pm Post subject: |
|
|
| Code: | | regsub {#} $chan {} chan |
Would be faster. It is neater also  _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Fri Apr 14, 2006 7:49 am Post subject: |
|
|
what about a simple [string trimleft $chan #] or [string map {# ""} $chan]? No need for any always slow regex.
| Code: | % time {set chan [string trimleft #channel.name #]} 100
2 microseconds per iteration
% time {set chan [string map {# ""} #channel.name]} 100
4 microseconds per iteration
% time {regsub {#} #channel.name {} chan} 100
7 microseconds per iteration |
First might make troubles when using with opnotices which target is @#channel, but if you want to strip then @# anyway, you will have no trouble with it. _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Fri Apr 14, 2006 8:19 pm Post subject: |
|
|
.. and a whole 2 microseconds is going to be a total disaster? Good grief! DragnLord's solution is not only neater but cuts code length. I prefer neat and short code. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Apr 14, 2006 8:39 pm Post subject: |
|
|
If you want it to still be neat but faster:
| Code: | | regsub {^#} $chan {} chan |
This will save time since it will check only the first character if it matches '#' instead of the whole string. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Fri Apr 14, 2006 9:04 pm Post subject: |
|
|
| Sir_Fz wrote: | If you want it to still be neat but faster:
| Code: | | regsub {^#} $chan {} chan |
This will save time since it will check only the first character if it matches '#' instead of the whole string. |
I would have thought so as well, until I ran the time tests.
| Code: | % time {regsub {#} #chan {} chan} 100
4.9 microseconds per iteration
% time {regsub {^#} #chan {} chan} 100
5.05 microseconds per iteration |
Maybe those time tests aren't really that accurate.  |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Fri Apr 14, 2006 9:25 pm Post subject: |
|
|
| DragnLord wrote: | Maybe those time tests aren't really that accurate.  |
They depend entirely on the efficiency of the computer they are being tested on. _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Fri Apr 14, 2006 9:33 pm Post subject: |
|
|
| Alchera wrote: |
They depend entirely on the efficiency of the computer they are being tested on. |
And I really can't see where microseconds will matter terribly (nor can I imagine a script where the exact same command is given in a procedure a hundred times in a row). |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Apr 15, 2006 6:03 am Post subject: |
|
|
Well, on my pc {^#} was faster
| Quote: | % time {regsub {^#} #chan chan} 10000
3.0633 microseconds per iteration
% time {regsub {#} #chan chan} 10000
3.2233 microseconds per iteration
% time {regsub {^#} #chan chan}
27 microseconds per iteration
% time {regsub {#} #chan chan}
28 microseconds per iteration |
But, it doesn't really matter, the difference isn't that big or near to big
Interrestingly, on 100 iterations {#} is faster:
| Quote: | % time {regsub {^#} #chan chan} 100
3.53 microseconds per iteration
% time {regsub {#} #chan chan} 100
3.37 microseconds per iteration |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
T-Xorcist Halfop
Joined: 14 Nov 2005 Posts: 47 Location: Netherlands
|
Posted: Sun Apr 16, 2006 5:24 am Post subject: |
|
|
Thank you all for giving me so much choice of doing it LoL!
Thnx!  _________________ is-1337.org IRC server! |
|
| Back to top |
|
 |
|