mIRC Home    About    Download    Register    News    Help

Topic Options
#157149 - 22/08/06 11:37 PM replace help
quiglag Offline
Ameglian cow

Registered: 04/01/03
Posts: 39
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

Top
#157150 - 23/08/06 12:34 AM Re: replace help
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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

Top
#157151 - 23/08/06 01:40 AM Re: replace help
quiglag Offline
Ameglian cow

Registered: 04/01/03
Posts: 39
awesome laugh Thanks a lot, works great.

Top
#157152 - 23/08/06 02:13 AM Re: replace help
quiglag Offline
Ameglian cow

Registered: 04/01/03
Posts: 39
Is there a way to use * in the list for partial matches?

Thanks

Top
#157153 - 23/08/06 02:49 AM Re: replace help
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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

Top
#157154 - 23/08/06 03:03 AM Re: replace help
quiglag Offline
Ameglian cow

Registered: 04/01/03
Posts: 39
cool. Thanks again. I will give them a try.

Top