Replaces tokens in a text with new tokens. Includes the option to replace all instances of a token.
;; ------- $reptoks by brinxy ------- ;;
;; About ;;
;; $reptoks is a slight enhancement to mIRC's regular $reptok. ;;
;; This identifier just allows you to put different tokens in at one time. ;;
;; -------------------------------------------- ;;
;; Snippet Syntax ;;
;; -------------------------------------------- ;;
;; $reptoks(string,Token,Newtoken,C)[.all]
;; - [string]: String to manipulate
;; - [Token]: Token to replace
;; - [Newtoken]: Token to insert at N/New token to replace old token
;; - [C]: Separator
;; -[.all]: Replaces all instances of a token in that text.
;; Please note that you can use Token and Newtoken multiple times in the syntax. (e.g $reptoks(string,Token,Newtoken,Token,Newtoken,C)[.all])
;; -------------------------------------------- ;;
;; Examples ;;
;; - $reptoks(insert token here,insert,put,here,there,32) returns "put token there"
;; - $reptoks(insert token here and insert a token there,insert,put,32).all returns "put a token here and put a token there"
;; Counter Examples ;;
;; - $reptoks(insert token here,put,give,there,here,32) returns $null
;; - There isn't a token named put and there isn't a token named there.
;; - $reptoks(insert token here,1,istok,2,etc,32) won't affect the token
;; - Token is a number
;; --------------------------------------------- ;;
alias reptoks {
var %0 = $($+($,$0),2), %x = 2,%returned = $1
while (%x < $0) {
if ($($+($,%x),2) isalpha) {
if (!$gettok(%returned,$ifmatch,%0)) { break }
elseif ($prop = all) { while ($findtok(%returned,$($+($,%x),2),%0)) { %returned = $puttok(%returned,$($+($,$calc(%x +1)),2),$ifmatch,%0) } }
else { %returned = $puttok(%returned,$($+($,$calc(%x +1)),2),$findtok(%returned,$($+($,%x),2),%0),%0) }
}
inc %x 2
}
return %returned
}