$reptok

From Scriptwiki
Revision as of 15:18, 23 May 2008 by Daveoh (talk | contribs) (N=0 update)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Replaces the Nth matching token in text with a new token.

$reptok(text,token,new,N,C)

If N is 0, replaces all matching tokens.

Note that $reptokcs() is the case-sensitive version.

Example

var %myoldtext = This is my old text
var %mynewtext = $reptok(%myoldtext, old, new, 1, 32)
echo -a %mynewtext

This example echoes This is my new text, as it replaced old with new.

var %numbers = 4,5,6,6,8,9
var %numbers = $reptok(%numbers,6,7,2,44)
echo -a %numbers

This echoes 4,5,6,7,8,9, as it replaced the second 6 with 7.

var %numbers = 0,1,2,0,2,2,0,1,2,1,0
echo -ag $reptok(%numbers,0,1,0,44)

This echoes 1,1,2,1,2,2,1,1,2,1,1 as all 0's are replaced with the number 1 due to N being 0.