mIRC Homepage
Posted By: quiglag replace help - 22/08/06 10:37 PM
hello,
Im looking for an alias that will act kind of like $replace($2,dog,cat,right,left...) but will read from a text file, so i dont have a $replace a mile long

Example of text file:
reads replace

dog cat
right left
up down


Can anyone help me?
Thanks
Posted By: RusselB Re: replace help - 22/08/06 11:34 PM
Presuming that your text file is called replace.txt and that it's in your mIRC directory, give this a try.
Code:
 alias replace.word {
  var %a = 1
  while %a <= $0 {
    var %word1 = $gettok($1-,%a,32)
    var %word2 = $iif($read(replace.txt,s,%word1),$v1,%word1))
    var %line = $replacex($1-,%word1,%word2)
    inc %a
  }
  $iif($isid,return,echo -a) %line
}
 

Usage: /replace.word <sentence>
or $replace.word(<sentence>)

The first usage will return the information as an echoed line in your active window.
The second usage will return the information to the calling script.

Change filename if necessary
Posted By: quiglag Re: replace help - 23/08/06 12:40 AM
awesome laugh Thanks a lot, works great.
Posted By: quiglag Re: replace help - 23/08/06 01:13 AM
Is there a way to use * in the list for partial matches?

Thanks
Posted By: RusselB Re: replace help - 23/08/06 01:49 AM
Yes, replace
Code:
 var %word2 = $iif($read(replace.txt,s,%word1),$v1,%word1)) 

with one of the following

1) Word must end with the item being searched (ie: searching for op would also catch stop)
Code:
 var %word2 = $iif($read(replace.txt,w,$+(*,%word1)),$v1,%word1)) 


2) Word must start with the item being searched (ie: searching for op would also catch ops)
Code:
 var %word2 = $iif($read(replace.txt,w,$+(%word1,*)),$v1,%word1)) 


3) Word can occur anywhere (ie: searching for op would also catch stops)
Code:
 var %word2 = $iif($read(replace.txt,w,$+(*,%word1,*)),$v1,%word1)) 


NOTE: These will replace the ENTIRE word, not just the portion of the word that matches
Posted By: quiglag Re: replace help - 23/08/06 02:03 AM
cool. Thanks again. I will give them a try.
© mIRC Discussion Forums