mIRC Home    About    Download    Register    News    Help

Print Thread
#217158 02/01/10 05:13 PM
Joined: Dec 2008
Posts: 16
M
MrUser Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Dec 2008
Posts: 16
Hello,
i would like to replace the %lists but only the tok witch have - ($chr(34))
Output should be: test|"-test"|test2|"-test2"|txt
Code:
alias replace {
  var %list = test|-test|test2|-test2|txt
  var %temp
  var %i = 1
  while (%i <= $numtok(%list,124)) {
    if ($chr(45) isin $gettok(%list,%i,124)) { 
    %temp = %temp $replce($gettok(%list,%i,124),$gettok(%list,%i,124),$chr(34) $+ $gettok(%list,%i,124) $+ $chr(34)) }
    inc %i
  }
  echo -a output: %temp
}

THX

Last edited by MrUser; 02/01/10 05:22 PM.

bye
MrUser #217159 02/01/10 05:31 PM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Code:
alias replace {
  var %list = test|-test|test2|-test2|txt, %i = 1
  while ($gettok(%list,%i,124)) { var %temp = $addtok(%temp,$iif($chr(45) isin $v1,$+(",$v2,"),$v2),124) | inc %i }
  echo -a output: %temp
}

Note: this will not work if there are duplicate entries in your %list. $addtok "adds a token to the end of [the] text but only if it's not already in [the] text."

Last edited by 5618; 02/01/10 05:34 PM.
5618 #217160 02/01/10 06:41 PM
Joined: Dec 2008
Posts: 16
M
MrUser Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Dec 2008
Posts: 16
Looks very nice and works good.
I don't have many duplicates, this i will change manually.

Thanks


bye
MrUser #217167 02/01/10 10:34 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Since you have a reply with a code that works, I'll just point out that your original code has a typo in it.

The $replace line uses $replce (notice the missing a)

MrUser #217169 03/01/10 08:26 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Here is the $regsubex() version if interested:
Code:
alias replace { echo -a output: $regsubex(test|-test|test2|-test2|txt,/(\55\w+)/Sg,$+(",\t,")) }
Or:
Code:
alias rep { $iif($isid,return,echo -a) $regsubex($1-,/(\55\w+)/Sg,$+(",\t,")) }
Then use:
Code:
/rep test|-test|test2|-test2|txt

or
Code:
//echo $rep(test|-test|test2|-test2|txt)

P.S. This also works for duplicate matches.

Tomao #217170 03/01/10 10:37 AM
Joined: Dec 2008
Posts: 16
M
MrUser Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Dec 2008
Posts: 16
RusselB, Yes,you're right :-)

Tomao, I am very happy, it works fantastically, many many thanks :-)


bye

Link Copied to Clipboard