mIRC Homepage

Strip a word

Posted By: Iljan

Strip a word - 12/09/05 08:25 PM

I have some problems, i have made a scripts that posts in to a db by a php page but the variable of the channel (#dutch in this case) wont be posted in to the db. frown

The problem is the # in the channelname. mad

How do i strip $chan from #dutch to just "dutch" and set it as %temp.channel ?
Posted By: MikeChat

Re: Strip a word - 12/09/05 08:37 PM

$remove(#channelname,$chr(35))
Posted By: SladeKraven

Re: Strip a word - 12/09/05 08:38 PM

Hi.

//set %temp.channel $gettok($chan,1,35)
//set %temp.channel $remove($chan,$chr(35))
//set %temp.channel $mid($chan,2-,$len($chan))
//tokenize 35 $chan | set %temp.channel $1

There's four examples of how you can do this. smile

Edit: Changed #dutch to $chan.

-Andy
Posted By: Riamus2

Re: Strip a word - 12/09/05 08:39 PM

set %temp.channel $remove($chan,$chr(35))

or

set %temp.channel $right($chan,-1)

EDIT: Sheesh. Can't even reply within 15 minutes without being beat to it by not one, but TWO people. laugh
Posted By: FiberOPtics

Re: Strip a word - 12/09/05 09:03 PM

Channel names can have multiple #'s in it, so using $remove would remove them all.

$mid($chan,2) is all one really needs, which does the same as your solution with $right.

Then again, maybe he didn't know that channel names can contain multiple #'s, and wants them all removed, which would mean the only good solution is, as you first suggested, $remove.
Posted By: Riamus2

Re: Strip a word - 12/09/05 09:49 PM

Yeah, I thought about channels having multiple #'s. smile

I didn't realize the length parameter was optional on $mid. Good to know. smile
Posted By: hixxy

Re: Strip a word - 12/09/05 09:53 PM

Or simply replace it with a character that's illegal in a channel name, for example: $replace($chan,$(#,),$chr(44))
Posted By: Riamus2

Re: Strip a word - 12/09/05 09:57 PM

Why?
Posted By: SladeKraven

Re: Strip a word - 12/09/05 10:03 PM

Well $chr(44) would not be a very good example to use but as you'd get: ,mIRC but..

$replace($chan,$(#,),$+($chr(32))) would be fine.
$replace($chan,$(#,),$+($chr(3))) would also be fine if characters after the '#' are not numeric.

-Andy
Posted By: Iljan

Re: Strip a word - 12/09/05 10:04 PM

Thankyou all for helping me out here, i used

set %temp.channel $gettok($chan,1,35)

And it works fine. Keep up the good work!!! smile
Posted By: hixxy

Re: Strip a word - 12/09/05 10:05 PM

So you can retrieve the correct channel name back later, for example:

My method:

Post: (mIRC) #w#e#i#r#d#c#h#a#n#n#e#l# -> (DB) ,w,e,i,r,d,c,h,a,n,n,e,l,
Retrieve: (DB) ,w,e,i,r,d,c,h,a,n,n,e,l, -> (mIRC) #w#e#i#r#d#c#h#a#n#n#e#l#

Your method:

Post: (mIRC) #w#e#i#r#d#c#h#a#n#n#e#l# -> (DB) weirdchannel
Retrieve: (DB) weirdchannel -> (mIRC) weirdchannel
Posted By: Riamus2

Re: Strip a word - 12/09/05 10:06 PM

That was why there was the second method posted. laugh
Posted By: FiberOPtics

Re: Strip a word - 12/09/05 10:08 PM

Replacing the #'s with a space will not be fine, since I've specifically stated that channel names can have multiple #'s in them.

It would turn the channel #andy#is#crazy to andy is crazy , which is no longer distinguishable as a channel from regular other text.
Posted By: Riamus2

Re: Strip a word - 12/09/05 10:11 PM

Hey, you might want to edit that to:

set %temp.channel $gettok($chan,1-,35)

Otherwise, you won't get the entire channel name if it has other #'s in it.

EDIT: Actually, that won't help either as it will remove the #'s.

You should use either of these instead:

set %temp.channel $mid($chan,2)
set %temp.channel $right($chan,-1)
Posted By: SladeKraven

Re: Strip a word - 12/09/05 10:12 PM

Well I guess so but I'd never attempt to join a channel with consecutive #'s in it, but if others actually do do it well then it was indeed wrong of me. smile

-Andy
Posted By: Iljan

Re: Strip a word - 12/09/05 10:14 PM

i used it in the following script:

on 1:join:#:{
if ($nick == $me) {
set %temp.channel $gettok($chan,1,35)
.sockopen devesteservjoin some.server.url 80
.timer12 1 2 .sockwrite -n devesteservjoin GET /beheer/update.php?action=join $+ &nick= $+ $me $+ &channel= $+ %temp.channel HTTP/1.0 $+ $crlf
.timer13 1 2 .sockwrite -n devesteservjoin Accept: */* $+ $crlf
.timer14 1 2 .sockwrite -n devesteservjoin User-Agent: mIRC $+ $crlf
.timer15 1 2 .sockwrite -n devesteservjoin Host: some.server.url $+ $crlf
.timer16 1 2 .sockwrite -n devesteservjoin $crlf
echo 4 -s Updating to server | set %chan.join $chan
}
}
on *:SOCKCLOSE:devesteservjoin:{ /echo 4 -s Http server updated, thank you - Join at %chan.join }
Posted By: FiberOPtics

Re: Strip a word - 12/09/05 10:18 PM

Hmm, why are you using timers to sockwrite to the connection? They serve no purpose as far as I can tell. Btw you don't need to put a $crlf after each header entry, since you are using the 'n' switch from sockwrite, which will append a $crlf already. Anyway, you've been helped accordingly, so I suppose this thread is finished.
Posted By: Riamus2

Re: Strip a word - 12/09/05 10:21 PM

Iljan, read me last post (and the edit).

If you try using a channel like #test#1, it won't work correctly as you have it right now. Granted, those types of channel names are few and far between, but better to be safe than sorry.
Posted By: hixxy

Re: Strip a word - 12/09/05 10:23 PM

All he said was that the # in the channel name was the problem, he didn't say it was only a problem if it was at the start of the text so using $right(#channel,-1) could still mess up for things like #channel#.
Posted By: SladeKraven

Re: Strip a word - 12/09/05 10:27 PM

You might want to add those sockwrite commands inside an IF statement to check if the socket is opened otherwise you'll get an error.

Code:
On me:*:Join:#: {
  set %temp.channel $gettok($chan,1-,35)
  .sockopen devesteservjoin some.server.url 80
}

on 1:Sockopen:devesteservjoin:{
  if ($sock(devesteservjoin)) {
    .sockwrite -n $v1 GET /beheer/update.php?action=join $+ &nick= $+ $me $+ &channel= $+ %temp.channel HTTP/1.0 $+ $crlf
    .sockwrite -n $v1 Accept: */* $+ $crlf
    .sockwrite -n $v1 User-Agent: mIRC $+ $crlf
    .sockwrite -n $v1 Host: some.server.url $+ $crlf
    .sockwrite -n $v1 $crlf
    echo 4 -s Updating to server | set %chan.join $chan  
  }
}


-Andy
Posted By: hixxy

Re: Strip a word - 12/09/05 10:30 PM

No. You don't need to check if the socket is open since you're inside the on sockopen event (which, surprisingly, triggers when a socket opens).
© 2020 mIRC Discussion Forums