mIRC Homepage
Posted By: Dylan666 separate tokens - 10/06/06 02:41 AM
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?
Posted By: Riamus2 Re: separate tokens - 10/06/06 02:56 AM
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
Posted By: Dylan666 Re: separate tokens - 10/06/06 06:39 AM
I tryed your script and it is perfetct thanks!
Posted By: Dylan666 Re: separate tokens - 10/06/06 06:58 AM
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...
Posted By: Riamus2 Re: separate tokens - 10/06/06 12:50 PM
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).
© mIRC Discussion Forums