mIRC Homepage
Posted By: AltReality string manipulation - 05/10/07 08:19 AM
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
Posted By: The_JD Re: string manipulation - 05/10/07 08:24 AM
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?
Posted By: The_JD Re: string manipulation - 05/10/07 08:25 AM
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
Posted By: genius_at_work Re: string manipulation - 05/10/07 02:19 PM
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
Posted By: AltReality Re: string manipulation - 05/10/07 05:37 PM
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
Posted By: DJ_Sol Re: string manipulation - 05/10/07 10:14 PM
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

Posted By: Lpfix5 Re: string manipulation - 06/10/07 12:28 AM
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
© mIRC Discussion Forums