mIRC Home    About    Download    Register    News    Help

Print Thread
#187422 05/10/07 08:19 AM
Joined: Mar 2004
Posts: 27
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Mar 2004
Posts: 27
Hi Everyone,

I have a string of text. It looks something like this.
Code:
0 000 XXX XXX 00 A|B|C|D E|F G H|I J|K|||L|M N|O|||P||Q|||R


I need to capture the A through the end of the line in a variable.

The data here is arbitrary...but the spacing is fairly well set...for example the 6th token (keyed on spaces) starts the data I want to capture.

The problem is, tokens 4 and 5 have varying lengths, so $left is out...and the data A-R may have spaces in different places...se $gettok(%text,6,32) gives me everything up to F...but I need everything after the F too...like $gettok(%text,6-,32) (but I know that's invalid syntax).

I could run a loop from 6 to $toknum(%text,32) and add it into the variable ...but that just seems kinda sloppy..

Could a $regex do it? something like %variable = $regex(%text,[A-Za-z]|*) or something?

Anyway..what are your thoughts...I know it can be done elegantly..but I'm just not sure how to do it.

Thanks for your help.
-AltReality

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
Code:
//var %text 0 000 XXX XXX 00 A|B|C|D E|F G H|I J|K|||L|M N|O|||P||Q|||R | echo -a $gettok(%text,6-,32)

Shows:
A|B|C|D E|F G H|I J|K|||L|M N|O|||P||Q|||R

Is this what you want?


[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
Just noticed you said thats invalid syntax, Not sure what you mean, mIRC will be happy with it...

Do you mean you can't use that for some particular reason? confused


Edit: If you can't use that code, be more specific and show a few examples of the actual strings you will get

Last edited by The_JD; 05/10/07 08:29 AM.

[02:16] * Titanic has quit IRC (Excess Flood)
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Did you try using the code in your example? $gettok(%text,6-,32) is completely valid in mIRC. In gettok you can use positive numbers, negative numbers, positive ranges, and negative ranges. Negative to positive ranges (-4-6) are not valid and simply default to a negative range with no end point (-4-). Example:

%text = a.b.c.d.e

$gettok(%text,2,46) -> b
$gettok(%text,2-3,46) -> b.c
$gettok(%text,2-,46) -> b.c.d.e
$gettok(%text,-3,46) -> c
$gettok(%text,-3-,46) -> c.d
$gettok(%text,-4--2,46) -> b.c.d

$gettok(%text,-4-4,46) -> b.c.d.e (invalid range)

-5 | -4 | -3 | -2 | -1
a . b . c . d . e
1 | 2 | 3 | 4 | 5

-genius_at_work

Joined: Mar 2004
Posts: 27
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Mar 2004
Posts: 27
Wow I feel like an idiot.
no, I didn't actually try it....but I looked at the help file and it wasn't documented, so I didn't think it was valid.

That help file is getting worse and worse smile

My fault all..thanks for clearing it up.

I should try it before I open my mouth next time.

wow. Thanks.
AltReality

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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


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



Im so in love with the $xxxtok commands, You are not a true scripter if you don't use $xxxtok commands in your script, just kidding. But really often you need to use it, even sometimes for simplest of all stuff a tok is in order the most popular ones for me is $gettok and $wildtok


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

Link Copied to Clipboard