mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2004
Posts: 526
HorseC Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Mar 2004
Posts: 526
Hi mirc lovers smile

I nee a little help with (i think) regex smile

I receive a notice from a bot and want to take the data passed and seperate it into variables..

An example (a notice to me slightly modified to hide some data) is this:

-botname- XXXXXXXXX '1''HorseC''HC_afk''founder''''male''us''xxxxxx N.Y.''0000-00-00''us,mirc''mIRC, scripting, Eggdrops, programming''horsec.jpg''xxxxx@sxxxxx.net''sales, strong computer background''http://forum.mirc.org''#mIRC'

The 'data' pairs represent the seperate parts i want to seperate, and as you may notice from the above exampe null parms passed are represented by a '' pair with no data inside.

What I would like to do (maybe in a loop?) is assign variable names to each of the pairs so i can use those variable in a dialog i have built (to pre fill the dialog) before display (edit box fill actually).
This will give me the ability to update a database without having to re-enter every field (only modify the ones that I
want to change)

I plan to use something like:

on 1:NOTICE:XXXXXXXXX*:?:{
...seperate parms and assign to variables

...build dialog to display here to display (have this part)

...process response from dialog sclick (have this part also)

}

Any help i could get with the seperation of the parms would be a great help!

(thanks in advance)

Last edited by HorseC; 07/06/10 04:08 AM.

Help others! It makes the world a better place, Makes you feel good, and makes you Healthy!
Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Perhaps "tokenise" can help? You would have to trust that the data is coming in a consistent form, whichever way you do it.

Partial script:

Code:
on 1:NOTICE:XXXXXXXXX*:?:{
tokenise asc(') $2-
var1 = $1
var2 = $2 etc
 

Note the restart from $1 after tokenising

Not tested, as I am not on mIRC, and "tokenise" is probably "tokenize", but "help" is your friend!

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Joined: Mar 2004
Posts: 526
HorseC Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Mar 2004
Posts: 526
thanks for the reply..

While I see how (maybe) a recurseive use of
$findtok(text,token,N,C)
might do the trick, there has to be an easier way..

Hoping for some other answers.


Help others! It makes the world a better place, Makes you feel good, and makes you Healthy!
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
*tok will ignore your null-parameters... Here's a quick regex shot:
Code:
alias parsetest {
  var %t = XXXXXXXXX '1''HorseC''HC_afk''founder''''male''us''xxxxxx N.Y.''0000-00-00''us,mirc''mIRC, scripting, Eggdrops, programming''horsec.jpg''xxxxx@sxxxxx.net''sales, strong computer background''http://forum.mirc.org''#mIRC'
  noop $regex(%t,/'([^']*)'/g)
  var %n = 1
  while (%n <= $regml(0)) { 
    var -s %chunk. $+ $v1 $regml($v1)
    inc %n
  }
}
Note that I don't know whether literal '-chars in the data are forbidden or will be quoted/escaped in some way. They likely will break the current expression. smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Regex is probably the best option, but just to show another method, you can also use $pos() combined with $mid().

Code:
alias stripdata {
  var %pos.s = 0, %pos.e = $pos($1-,',1), %c = 1
  while (%pos.e) {
    var %data. $+ %c $mid($1-,%pos.s,$calc(%pos.e - %pos.s))
    inc %c
    var %pos.s = %pos.e, %pos.e = $pos($1-,',%c)
  }
}


Note that this leaves the leading ' on each variable. This allows you to have null variables as they will have a ' in them. You can easily remove the ' when adding to your dialog. Variables would be %data.1 - %data.32 .

Again, regex is probably much better, but this is just to show another method for anyone learning mIRC scripting.

Edit: Testing this with the regex above gives 15-16 ms each (removing the /var %t line in the regex script and using $1- so there isn't an extra /var to take up time), so there doesn't appear to be any noticeable difference in speed between them. smile

Last edited by Riamus2; 07/06/10 11:45 AM.

Invision Support
#Invision on irc.irchighway.net
Joined: Mar 2004
Posts: 526
HorseC Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Mar 2004
Posts: 526
Thanks to both Horstl and Riamus2 for the quick responses.

I will try both of these and determine which works best for me wink

Its quick responses to questions like this that makes it such
a pleasure to use mIRC as my IRC client. Great work guys!


Help others! It makes the world a better place, Makes you feel good, and makes you Healthy!

Link Copied to Clipboard