mIRC Home    About    Download    Register    News    Help

Print Thread
#157149 22/08/06 10:37 PM
Joined: Jan 2003
Posts: 39
Q
quiglag Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Jan 2003
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

#157150 22/08/06 11:34 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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

#157151 23/08/06 12:40 AM
Joined: Jan 2003
Posts: 39
Q
quiglag Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Jan 2003
Posts: 39
awesome laugh Thanks a lot, works great.

#157152 23/08/06 01:13 AM
Joined: Jan 2003
Posts: 39
Q
quiglag Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Jan 2003
Posts: 39
Is there a way to use * in the list for partial matches?

Thanks

#157153 23/08/06 01:49 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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

#157154 23/08/06 02:03 AM
Joined: Jan 2003
Posts: 39
Q
quiglag Offline OP
Ameglian cow
OP Offline
Ameglian cow
Q
Joined: Jan 2003
Posts: 39
cool. Thanks again. I will give them a try.


Link Copied to Clipboard