mIRC Homepage
Trying to solve a problem here but can't find any solution, maybe someone here does.

I have a line to strip a specific word but i can only tell for sure it's the third word from the right instead of left

example:
(a bunch of words, can be 6 but also less or more) [SPECIFICWORD] (always 2 words!)

I tried to strip with using $left $right $strip etc but no way i can get it to start at the end of line instead of beginning.
Is this even possible?

if you want to remove the word:

Code:
//echo -a $deltok(line,-3,32)


if you want to retrieve the word:

Code:
//echo -a $gettok(line,-3,32)


check out /help token identifiers
Thanks but it doesn't seem to work.
It returns nothing.

on sitebot:TEXT:*hello*:#testnet:{
if ($nick == test) | set %curtime $gettok(line,-3,32) }
{ z.greet }
}

Doesn't matter what kind of line i make but var %curtime stays empty.
Code:
on sitebot:TEXT:*hello*:#testnet:{
  if ($nick == test) { set %curtime $gettok(line,-3,32) }
}

Try something like that instead..
Code:
on sitebot:TEXT:*hello*:#testnet:{
  if ($nick == test) { set %curtime $gettok(line,-3,32) }
}


Sorry if my question has nothing to do with the question.
but i just want to know what is on sitebot:

if the
on me: targets myself

because it said

if ($nick == test)

Originally Posted By: nomer2007

i just want to know what is on sitebot:

if the
on me: targets myself

because it said

if ($nick == test)



Please see this post...
https://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=190355&Main=35153#Post190355
so if we use on me prefix

we could use

Quote:
on othernick:


too?

One would think that it would work that way, but no it doesn't. Only ME.
Originally Posted By: Bekar
Code:
on sitebot:TEXT:*hello*:#testnet:{
  if ($nick == test) { set %curtime $gettok(line,-3,32) }
}

Try something like that instead..
Tried it but not working, i guess i'm lost here ¿

I have made just a simple piece of code just to show me something , but it does nothing!

Code:
on *:TEXT:*hello*:#testnet:{
  set %curtime $gettok(line,-3,32)
  /echo -a hello
  /echo -a $+ %curtime $+
}


Isn't there an extended tutorial that shows in detail what you all can use with $gettok what options you can have/set and some examples.

I have read the default mirc help file did some searches on the web but they all show me the same stuff

Quote:
$gettok(text,N,C)
Returns the Nth token in text.
$gettok(a.b.c.d.e,3,46) returns c
$gettok(a.b.c.d.e,9,46) returns $null
You can also specify a range of tokens:
$gettok(a.b.c.d.e,2-,46) returns 2nd token onwards b.c.d.e
$gettok(a.b.c.d.e,2-4,46) returns tokens 2 through 4 b.c.d
You can specify a negative value for N.
Originally Posted By: ots654685
[quote=Bekar]
Code:
on sitebot:TEXT:*hello*:#testnet:{
  if ($nick == test) { set %curtime $gettok(line,-3,32) }
}

Try something like that instead..


Have you replaced 'line' with $1- in the $gettok(line,-3,32) ?

Quote:

Code:
on *:TEXT:*hello*:#testnet:{
  set %curtime $gettok(line,-3,32)
  /echo -a hello
  /echo -a $+ %curtime $+
}



Here also, 'line' should be replaced by $1- for the script to function correctly.

Regards smile
@TropNul

That solved it thanks.
Maybe you can tell me where to get more info on this fucntions instead of mirc help?
The mIRC help file is the best place to start on token identifiers. There may be some token tutorials out there (google will tell you where wink ) but as others will say, the mIRC help file is really clear and simple in its explanations on tokens.

In my opinion, one should read the mIRC help file thouroughly. I've started scripting by reading it. I read many tutorials but always came back to the mIRC help file.

Now, if you have any question about a function just ask us here.

For the $gettok identifier, as the help file says, it's usage is to retrieve (get) a token from a string where each word is separated by the character C.

$gettok(string,token,C)

where 'token' is a number defining the token needed.

For example:

//echo > $gettok(this is a simple test,1,32)
returns > this

//echo > $gettok(this is a simple test,1-3,32)
returns > this is a

//echo > $gettok(this is a simple test,1-,32)
returns > this is a simple test

//echo > $gettok(this is a simple test,-1,32)
returns > test

Make the tests to see the behaviour. There's no more to know about $gettok. If you understand this, then you know $gettok wink .

NB: the 32 in each case is used to specify that the separating character is the space and its ASCII value (32) is used. Thus, if a string is separated by periods '.', the separating character would be 46.

Have faith in the help file smile .

Regards
@TropNul

Thanks, reading the documentation now. But i was wondering if it is possible to get a block of words this way?
Now the gettok function just grabs 1 word.

Look at his second example, it grabs tokens 1-3

//echo > $gettok(this is a simple test,1-3,32)
returns > this is a

//echo > $gettok(this is a simple test,2-4,32)
returns > is a simple


Also check out $mid

//echo > $mid(ABCDEFGHIJKLMNOPQRSTUVWXYZ,10,10)
returns > JKLMNOPQRS

/help $mid
Quoting the helpfile:
Quote:
You can also specify a range of tokens (...) You can specify a negative value for N.
e.g.
$gettok(seven six five four three two one,-5--3,32)
returns: "five four three"

$gettok(text,N[-N2],C)
$gettok(text,number or range of token(s),token-delimiter)
text is: seven six five four three two one,
the range is: -5 to -3 (5th-last to 3rd-last token (negative N),
tokens are separated by: space (ascii value 32)

mmm i missed that i guess anyway, i'm trying to solve a problem i can't get the correct answer for.
I'm in a situation that i need to grab a variable group of words at the end of line, sometimes it are 3 and sometimes 2 or maybe just 1.
So i'm struggling on how to detect such group. and grab it.

My first thought was to grab always max size but then i could have a incorrect group.
My second idea was to check if groups exists in complete line like this:

Code:
var %line $strip($1-)
if (*a+*b+*c iswm %autoline) { $gettok($1-,5-3,32) }
if (*b+*c iswm %autoline) { $gettok($1-,4-3,32) }
if (*c iswm %autoline) { $gettok($1-,3,32) }


But it ain't working, i guess this "*a+*b+*c" is incorrect format and second there to much words that have a "c" in it so that isn't an option to.
Any ideas?

Ok guys wouldnt regex be suitable here? To grab a specific range else then that all I can say is play with $numtok or $wildtok with $gettok

EDIT: What is the actual line of input your trying to get specific words/groups out of it would maybe help if we saw it.
Originally Posted By: Lpfix5
Ok guys wouldnt regex be suitable here? To grab a specific range else then that all I can say is play with $numtok or $wildtok with $gettok

EDIT: What is the actual line of input your trying to get specific words/groups out of it would maybe help if we saw it.


Line could be something like:

Quote:
This user is last seen 1m 3w 5d ago.
Or
User is last seen 2w 3d ago.
without any regex, but using some text identifiers ($mid $pos $len) for example:
var %text = This user is last seen 1m 3w 5d ago.
echo -a $deltok($mid(%text,$calc($pos(%text,last seen) + $len(last seen))),-1,32)

$deltok($mid(%text,[color:#FF6600]$calc([color:#FF0000]$pos(%text,last seen) + $len(last seen))[/color])[/color],-1,32)

$pos > the starting position of the string "last seen" in the text
$len > the length of the string "last seen"
$calc(pos +len) > the end position of the string "last seen" in the text
$mid > text from position X onwards
$deltok > remove last token (the "ago.")
in one command... >=]

var %a = This user is last seen 1m 3w 5d ago.
$remove(%a,This,user,is,last,seen,ago.)

Strips both methods you shown smile
sure grin
I think my example is more educative to some degree, as it tries some dynamic text picking - but then, yours is shorter, faster, and last but not least: more comprehensible wink
Indeed long story short stripping a specific word or group of words out of context is quite easy and can be done in not 1 not 2 but many several ways.

all with $findtok $gettok and $calc Its possible "First find seen token" then Find "Ago." token then gettok calc + 1 for the seen token and minus 1 for the ago. token smile But it''s rather lengthy

I made up what I call $mrgtok it consits of $findtok within gettok range in multiple areas. Why? Well I seem to always be using $findtok and $gettok in alot of my scripts
Thanks Horstl and Lpfix5,

Going to play and learn from it this weekend, gonna try if you can make it prefixed line independent so that it just triggers on : *m+*w+*d or *w+*d or just *d.

I'm not an average scripter more an avbg hoping to learn from it
Uh, if you want a wildmatch for this kind of "duration in textstring", I suppose a regex is most suitable -at last-.
I'm not that firm with regex, - atm it will match only if m AND w AND d are provided... I have probs to handle the spaces... but for sure someone that reads this can improve my poor attempt smile
Also note, that whatever regex/other method used, it inevitable will match statements like "Hey, I bought a new 3d game!
Code:
on *:text:*:#: {
  noop $regex($1-,/((?:\d+m)? (?:[1-3]w)? (?:[1-6]d)?)/S)
  if ($regml(1)) { echo -a match: $regml(1) }
}
Is it possible to change the outcome of that incoming mesage instead of 1w 3d to be like 1week 3days? or you have no control on the incoming message?

Because to make a solid pickup you would in theory need it to be more tight in the way to pick up the (y)ear (m)onth (d)ays

The only way to make it tighter is if theres atleast 2 matching num symbols example.

Lets say for sure the output would be 2m 1w 6d is when I seen NICK

then..

Using regex like this..

Code:
on *:TEXT:*:#:{
if ($regex($1-,/\b(\d+m|[1-3]w|[1-6]d)\b/g) >= 2) { echo -a $regml(1) $regml(2) $regml(3) }
}


Will only function if theres a matching event that is 2 or higher meaning if 3d is the only word in it will not function but if 2w 3d will.

The downfall if by any chance, 1d or 1m or 1w is the only output then the script does not launch, but if you know where im coming from, If the script shows this 3d 8h 7s ago. then you could expand your regex match. so make it work as you wish.

In the code I put youll see $regml(1) up to 3 it doesnt matter if theres only 2 matches the 3rd regml won't trigger.
I was thinking of fetching all possibly strings that do that, and put them into a hash or txt file then read from file and parse as will..

Example...

Exactly 2w 5d is when I last seen nick.
I seen nick 2w 5d ago.
Nick was seen 2w 5d ago.

This would give me 3 options to go about. But then again it might defeat the purpose of your w m d rules.
Originally Posted By: Lpfix5
Is it possible to change the outcome of that incoming mesage instead of 1w 3d to be like 1week 3days? or you have no control on the incoming message?
Actually i haven't got any control on it and i had plans using it for more then 1 channel and not every channel uses same style.


Quote:
Because to make a solid pickup you would in theory need it to be more tight in the way to pick up the (y)ear (m)onth (d)ays

The only way to make it tighter is if theres atleast 2 matching num symbols example.

Lets say for sure the output would be 2m 1w 6d is when I seen NICK

then..

Using regex like this..

Code:
on *:TEXT:*:#:{
if ($regex($1-,/\b(\d+m|[1-3]w|[1-6]d)\b/g) >= 2) { echo -a $regml(1) $regml(2) $regml(3) }
}


Will only function if theres a matching event that is 2 or higher meaning if 3d is the only word in it will not function but if 2w 3d will.

The downfall if by any chance, 1d or 1m or 1w is the only output then the script does not launch, but if you know where im coming from, If the script shows this 3d 8h 7s ago. then you could expand your regex match. so make it work as you wish.

In the code I put youll see $regml(1) up to 3 it doesnt matter if theres only 2 matches the 3rd regml won't trigger.
You said that if it's bigger then 2 it will function, but what if we splits it and check for <= 52 for weeks <=12 for months and <=31 for days?
Then we have all options and the change it picks wrong format is hardly there, or do i forget something?

-update-
Still struggling with regex function, so no preview code yet
Originally Posted By: ots654685
You said that if it's bigger then 2 it will function, but what if we splits it and check for <= 52 for weeks <=12 for months and <=31 for days?
Then we have all options and the change it picks wrong format is hardly there, or do i forget something?

The $duration output of the given examples breaks at 7days > 1week, 4weeks > one month - Thus you'll always run into problems like
"I need a new 3d video card"
"from my house it's only 600m to the local store"

There's need for some other kind of checking... For example, if this would be a reply to a !seen script, a group enabled only for a couple of seconds on text !seen
Imo, the function
Code:
Alias GetSeen {
  If $regex($1-,/(seen\s\b(\d{1,}m\s\d{1,}w\s\d{1,}d|\d{1,}w\s\d{1,}d|\d{1,}d)\sago\.$)/iS) {
    Echo -ast $regml(2)
  }
}

echoes what you want.

I don't know about the further processing on the result of the function. For instance, if you want to get piecewise returns, then a simple < /tokenize 32 $regml(2) > would do that by allocating to $1 $2 .. $n each spaced token.

It could ressemble this code.
Code:
Alias GetSeen {
  If $regex($1-,/(seen\s\b(\d{1,}m\s\d{1,}w\s\d{1,}d|\d{1,}w\s\d{1,}d|\d{1,}d)\sago\.$)/iS) {
    Tokenize 32 $regml(2)
    Echo -st $*
  }
}


Of course, these codes are only for demonstrating how you can grab the desired format. And, there is for sure, better regular expressions that could be used. This one functions though.

Cordialement smile

PS: If you need whichever explanation, just ask us.
© mIRC Discussion Forums