mIRC Home    About    Download    Register    News    Help

Print Thread
separate tokens #150842 10/06/06 02:41 AM
Joined: Aug 2003
Posts: 50
D
Dylan666 Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Aug 2003
Posts: 50
I have this list:

[settings]
Things=colorRed,colorBlue,colorBrown,nameTeddy,nameRosy,colorWhite,nameRod

How can I separate the color tokens from the name tokens, delteting the prefix parte (color) and put thenin a new token list or variable list?

Re: separate tokens #150843 10/06/06 02:56 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Code:
alias convert {
  var %settings = $readini(file.ini,Settings,Things)
  var %counter = 1
  while (%counter <= $gettok(%settings,0,44)) {
    if (color* iswm $gettok(%settings,%counter,44)) {
      var %colors = %colors $remove($gettok(%settings,%counter,44),color) $+ ,
    }
    if (name* iswm $gettok(%settings,%counter,44)) {
      var %names = %names $remove($gettok(%settings,%counter,44),name) $+ ,
    }
    inc %counter
  }
}


Just replace file.ini with the filename of where your settings are stored. Or just replace the entire $readini part with the data you have there.

This will give you 2 variables to use as you want -- %colors and %names

To use, just type /convert


Invision Support
#Invision on irc.irchighway.net
Re: separate tokens #150844 10/06/06 06:39 AM
Joined: Aug 2003
Posts: 50
D
Dylan666 Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Aug 2003
Posts: 50
I tryed your script and it is perfetct thanks!

Last edited by Dylan666; 10/06/06 06:43 AM.
Re: separate tokens #150845 10/06/06 06:58 AM
Joined: Aug 2003
Posts: 50
D
Dylan666 Offline OP
Babel fish
OP Offline
Babel fish
D
Joined: Aug 2003
Posts: 50
Just a little more difficult:

[Settings]
Categories=name,color,animal
Things=colorRed,colorBlue,colorBrown,nameTeddy,nameRosy,colorWhite,nameRod,animalElephant,animalLion,nameMary,animalPenguin,colorBlack

How two divide the second list using the Categories tokens if I don't know their names (name, color, etc.)?

Well, I suppose I should use two "while" cycles, the first to try each Categories word and the second to extract the relative tokens from the Things list...

Re: separate tokens #150846 10/06/06 12:50 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Code:
alias convert {
  var %names = $readini(file.ini,Settings,Categories)
  var %things = $readini(file.ini,Settings,Things)
  var %name.cnt = 1
  var %thing.cnt = 1
  while (%name.cnt <= $gettok(%names,0,44)) {
    var %name = $gettok(%names,%name.cnt,44)
    while (%thing.cnt <= $gettok(%things,0,44)) {
      if (%name $+ * iswm $gettok(%things,%thing.cnt,44)) {
        var %data = %data $remove($gettok(%things,%thing.cnt,44),%name) $+ ,
      }
      inc %thing.cnt
      if (%thing.cnt > $gettok(%names,0,44)) {
        echo -a %name = %data
      }
    }
    inc %name.cnt
  }
}


That should separate your data the way you want and echo it. You'd just need to change the echo line to do whatever it is you want to actually happen (perhaps writeini or something).


Invision Support
#Invision on irc.irchighway.net