mIRC Homepage
Posted By: wouziap how to count spaces in the text? - 23/04/05 09:07 AM
how to count spaces in the text?

$count(viskas yra gerai,$chr(160))
Posted By: aDevil Re: how to count spaces in the text? - 23/04/05 09:16 AM
$count(viskas yra gerai,$chr(32)) wink

Have fun!
Posted By: RusselB Re: how to count spaces in the text? - 23/04/05 12:23 PM
It's always a better idea to use $chr(32) when referencing spaces, since $chr(160) looks like a space character in a lot of fonts, it doesn't look like that in all fonts, and the ascii value assigned to the space bar is 32...therefore $chr(32) will represent a space character no matter what font is being used.
Posted By: SladeKraven Re: how to count spaces in the text? - 23/04/05 01:23 PM
Another way without using $count() would be calculating the number of space delimited tokens and subtracting 1 from that total.

You can use $0 to return the number of space delimited tokens. Or $numtok($1-,32).

//echo -a $calc($numtok(viskas yra gerai,32) - 1)

Code:
alias spaces { 
  return $calc($numtok($$1-,32) - 1)
}


And with that alias you can then do something like..

//echo -a $spaces(viskas yra gerai)

Code:
on *:Text:*:#: {
  if ($spaces($1-) < 1) { msg $chan You are supposed to use atleast one space $nick | halt }
}


-Andy
Posted By: FiberOPtics Re: how to count spaces in the text? - 23/04/05 01:45 PM
Just two little notes.

1. If someone msgs a space to a channel, $numtok - 1 will be -1, while there is indeed a space. $0 returns 0.
2. In the on text event, incoming $N parameters are space delimited, so you don't need a custom identifier to determine if there are spaces.

if $0 == 1 { msg # $nick : you should atleast use one space }

If you want to exclude a single space from being valid, it's easily changed to if $0 < 2
Posted By: Sigh Re: how to count spaces in the text? - 23/04/05 06:46 PM
It shouldn't be possible to send a blank space to a channel (you'll get a 'PRIVMSG Not enough parameters' or 'No text to send' error on most if not all networks if you try) so $0 is guaranteed to be at least 1

Another method to get number of spaces, shorter than $count in this case, is of course $regex(text,/ /g)
Posted By: FiberOPtics Re: how to count spaces in the text? - 23/04/05 07:28 PM
Quote:
so $0 is guaranteed to be at least 1

That's incorrect.

Just press the spacebar and then ctrl+enter.

$0 will be 0, and the on text event triggered it.

Not saying it's like this on all networks, but atleats on one of the big ones (Dalnet) this is the case.

I usually test things before I post them :tongue:, not just gonna post something if I can't back it up.
Posted By: Riamus2 Re: how to count spaces in the text? - 23/04/05 10:22 PM
Isn't $chr(160) and non-breaking space? Been too long since I messed with non-breaking spaces.
Posted By: SladeKraven Re: how to count spaces in the text? - 23/04/05 10:25 PM
Yes, it is.
Posted By: FiberOPtics Re: how to count spaces in the text? - 23/04/05 10:37 PM
on *:text:*:#channel:{
msg # -> $asc($1) ** $0
}

When msging with a clone a space by pressing space bar and ctrl+enter it messages back to the channel:

-> ** 0

When msging with a clone a hard space $chr(160) like //msg # $chr(160), it messages back to the channel:

-> 160 ** 1

This is on Dalnet.

$chr(160) is a hard space on a lot of fonts, but certainly not on all, there are various where it represents another character. Not many people seem to be understanding this.
Posted By: Kelder Re: how to count spaces in the text? - 23/04/05 11:40 PM
if you need to count spaces in an on TEXT or NOTICE or ACTION event, you could try something like this
on *:TEXT:*:#:{
var %numberofspaces = $regex($gettok($rawmsg,2-,58),/[  ]/g)
}

Note that it reads /[<$chr(32)><$chr(160)>]/g so you count both types (real spaces and filler stuff). You can ofcourse just put $regex($gettok($rawmsg,2-,58),/ /g) if you need only real spaces or $regex($1-,/ /g) if you only need those $chr(160) fake spaces...

Going around to $rawmsg is needed since mIRC handles (real) spaces as delimiters, and just keeps one delimiter if multiple are found.
Posted By: Sigh Re: how to count spaces in the text? - 24/04/05 02:07 AM
Good idea but the problem with : as a delimiter is that channel names on quite a few networks, as well as ipv6 addresses, can include that character so you're not always getting the actual text alone. $gettok also strips excess delimiters so that will change the user's message if they typed a bunch of :::s. $mid should be used instead:

Code:
$mid($rawmsg,$calc(2+$pos($rawmsg,$chr(32),3)))
Posted By: Kelder Re: how to count spaces in the text? - 24/04/05 08:03 AM
Hmm, you're right about those :'s appearing in address/chann blush The $gettok removing double :'s is not my problem though, I was only interested in counting spaces smile

Since there are always 3 spaces before the message, $calc($regex($rawmsg,/ /g) - 3) counts all spaces in the message.

For counting only $chr(160)'s it's still the $regex($1-,/ /g) line. For the combination it's more difficult ($chr(160) can appear in channel names), so either your $mid solution or just summing both single cases grin
© mIRC Discussion Forums