mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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?


Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
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


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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.

Joined: Dec 2002
Posts: 503
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Code:
on sitebot:TEXT:*hello*:#testnet:{
  if ($nick == test) { set %curtime $gettok(line,-3,32) }
}

Try something like that instead..

Joined: Oct 2007
Posts: 92
N
Babel fish
Offline
Babel fish
N
Joined: Oct 2007
Posts: 92
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)

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

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

Joined: Oct 2007
Posts: 92
N
Babel fish
Offline
Babel fish
N
Joined: Oct 2007
Posts: 92
so if we use on me prefix

we could use

Quote:
on othernick:


too?

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

One would think that it would work that way, but no it doesn't. Only ME.

Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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.

Last edited by ots654685; 20/11/07 10:59 AM.
Joined: May 2007
Posts: 89
T
Babel fish
Offline
Babel fish
T
Joined: May 2007
Posts: 89
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
Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
@TropNul

That solved it thanks.
Maybe you can tell me where to get more info on this fucntions instead of mirc help?

Joined: May 2007
Posts: 89
T
Babel fish
Offline
Babel fish
T
Joined: May 2007
Posts: 89
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
Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
@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.

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

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

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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)


Last edited by Horstl; 20/11/07 10:56 PM.
Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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?


Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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.

Last edited by Lpfix5; 22/11/07 07:17 PM.

Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Feb 2006
Posts: 97
O
Babel fish
OP Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
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.

Last edited by ots654685; 22/11/07 09:21 PM.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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.")

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Page 1 of 2 1 2

Link Copied to Clipboard