mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
$strip words beginning from right instead of left #190337 19/11/07 10:55 AM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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?


Re: $strip words beginning from right instead of l [Re: ots654685] #190338 19/11/07 10:59 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
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
Re: $strip words beginning from right instead of l [Re: jaytea] #190342 19/11/07 12:23 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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.

Re: $strip words beginning from right instead of l [Re: ots654685] #190346 19/11/07 02:38 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
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..

Re: $strip words beginning from right instead of l [Re: Bekar] #190353 19/11/07 04:24 PM
Joined: Oct 2007
Posts: 92
N
nomer2007 Offline
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)

Re: $strip words beginning from right instead of l [Re: nomer2007] #190356 19/11/07 05:13 PM
Joined: Dec 2002
Posts: 2,024
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,024

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...
http://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=190355&Main=35153#Post190355

Re: $strip words beginning from right instead of l [Re: RoCk] #190361 19/11/07 06:45 PM
Joined: Oct 2007
Posts: 92
N
nomer2007 Offline
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?

Re: $strip words beginning from right instead of l [Re: nomer2007] #190364 19/11/07 07:01 PM
Joined: Dec 2002
Posts: 2,024
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,024

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

Re: $strip words beginning from right instead of l [Re: Bekar] #190399 20/11/07 10:59 AM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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.
Re: $strip words beginning from right instead of l [Re: ots654685] #190400 20/11/07 11:58 AM
Joined: May 2007
Posts: 89
T
TropNul Offline
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
Re: $strip words beginning from right instead of l [Re: TropNul] #190403 20/11/07 12:33 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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?

Re: $strip words beginning from right instead of l [Re: ots654685] #190406 20/11/07 02:15 PM
Joined: May 2007
Posts: 89
T
TropNul Offline
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
Re: $strip words beginning from right instead of l [Re: TropNul] #190430 20/11/07 10:30 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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.

Re: $strip words beginning from right instead of l [Re: ots654685] #190431 20/11/07 10:32 PM
Joined: Dec 2002
Posts: 2,024
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,024

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

Re: $strip words beginning from right instead of l [Re: ots654685] #190433 20/11/07 10:48 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
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.
Re: $strip words beginning from right instead of l [Re: Horstl] #190551 22/11/07 03:51 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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?


Re: $strip words beginning from right instead of l [Re: ots654685] #190556 22/11/07 04:54 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
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* }
Re: $strip words beginning from right instead of l [Re: Lpfix5] #190577 22/11/07 09:21 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline OP
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.
Re: $strip words beginning from right instead of l [Re: ots654685] #190580 22/11/07 10:04 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
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.")

Re: $strip words beginning from right instead of l [Re: Horstl] #190592 23/11/07 05:33 AM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
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