mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2005
Posts: 21
W
wouziap Offline OP
Ameglian cow
OP Offline
Ameglian cow
W
Joined: Feb 2005
Posts: 21
how to count spaces in the text?

$count(viskas yra gerai,$chr(160))

Joined: Apr 2005
Posts: 53
A
Babel fish
Offline
Babel fish
A
Joined: Apr 2005
Posts: 53
$count(viskas yra gerai,$chr(32)) wink

Have fun!

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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


Gone.
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
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)

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Isn't $chr(160) and non-breaking space? Been too long since I messed with non-breaking spaces.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Yes, it is.

Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
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.

Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
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)))

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
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


Link Copied to Clipboard