mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2006
Posts: 2
G
Gamez0r Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
G
Joined: Nov 2006
Posts: 2
//echo -a $numtok(R R V V V V O C F F F,79) - $chr(79) // $numtok(R R V V V V O C F F F,33) - $chr(33)

(results) 2 - O // 1 - !

I use Windows 98SE; mIRC 6.20, in no way are those identifiers edited/customized.

It seems to randomly happen; sometimes it returns the right ammount, other times it returns 1 more then it should. If later I test it again; it returns different results; like some characters will have the correct numbers & the other will have +1.

At all times it returns if there is 0; 1. Is there a +1 error or something? lol

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
This is how it should work. If you have no token separator in the line, then it should return 1. In the second part of your example, because you have no ! separator, you have 1 token. There will always be 1 more token than you have separators for.

Assume I'm checking the number of tokens with a space as the token separator...
AA = 1 token (0 separators)
AA AAA = 2 tokens (1 separator)
AA AAA AAAA = 3 tokens (2 separators)

Think of tokens like words. If I wrote 1 word and nothing else, it's still a word (token). If I write 2 words, then there is 1 space and two words (tokens).


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
It all depends on how you look at tokens
$numtok(a,33)
returns 1 because if theres no character to split the string the entire string becomes the first token.

reason why $numtok(a,33) and $numtok(a!,33) are the same is because mirc ignores NULL tokens. Which is why $numtok(a!!a,33) will return 2.


$maybe
Joined: Nov 2006
Posts: 2
G
Gamez0r Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
G
Joined: Nov 2006
Posts: 2
So how come when I return a specific token (like the O), it returns 2? It only found the token once in the whole line.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
It returns 2 because that's how many tokens are delimited by the "O".

R R V V V V O C F F F

1st "O" delimited token
2nd "O" delimited token

If for example the string contained a second "O" and looked something like this: R R V V V V O C F F F O A S D F

Then, in that case there would be 3 tokens, the third being A S D F. If the second O was present, but the A S D F was not, then there would be only 2 tokens because nothing comes after the second O.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
As I said, think of tokens like words. It will really help you to understand it. Example: $numtok(this is an example,32)

32 is a space, so it lets us look at it based on "words" rather than trying to understand based on other deliminators/separators.

I'm sure you will agree that there are 4 words there. But, how many spaces are there? 3.

Also, if you had: "this is an example " (notice the space after example), you will still have only 4 words. Even though there is that space, you would never say that there are 5 words there, right?

Now, if it was only 1 space (think of the space as if it were an O in your example)...

Hello again.

How many words? 2. Here it is with an O...

HelloOagain.

That's still 2 words if you think of the O as the deliminator/separator instead of a space.


Invision Support
#Invision on irc.irchighway.net
Joined: Nov 2004
Posts: 842
Hoopy frood
Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
On the risk of being ridiculed, why not use $count() or $countcs() for counting letters or a string?


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Um...?

$numtok(R R V V V V O C F F F,79) won't give you the same answer as $count. He isn't counting letters (79 isn't a space).


Invision Support
#Invision on irc.irchighway.net
Joined: Nov 2004
Posts: 842
Hoopy frood
Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
I thought he was trying to count how many times the token O appears in the string using $numtok.


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ah. Well, maybe he is since he seems to want it to be one less than $numtok should give.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
Quote:

Also, if you had: "this is an example " (notice the space after example), you will still have only 4 words. Even though there is that space, you would never say that there are 5 words there, right?


If you translate this to an example with 'O', then you have:

"thisOisOanOexampleO" - there are the same number of tokens as in Riamus2's example (4), they happen to be delimited by 'O' instead of ' ' (space), here.

mIRC does not count null tokens, either, so:

"thisOOisOanOOexample"

still has four tokens ('this', 'is', 'an', and 'example') (but there are 5 delimiters). There is no token between either the first and second 'O', or between the 4th and 5th 'O'.


Sais
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I actually did make that with O's already, though with only 2 words. laugh

Anyhow, he should understand by now. We've given plenty of examples and explanations.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
I was trying to emphasise the 'extra delimiter on the end'. But, yes, plenty of examples laugh


Sais

Link Copied to Clipboard