Ray Yates
: mivascript at, pcinet d0t com
08/02/2011 23:05 p.m.
08/02/2011 23:05 p.m.
Replace(): Replaces a single case sensitive occurance of a substring within a string. Accepts a starting search position (usually 1). Start must be a variable and is changed to the first character position AFTER the replaced string. Unlike the glosub() function which replaces all matches, the replace() function gives you more control over what to replace and where to begin searching.
<MvFUNCTIONNAME="Replace"PARAMETERS="string, search, replace, start VAR"STANDARDOUTPUTLEVEL=""><MvCOMMENT> <MvASSIGN NAME="g.string" VALUE="{ 'Now is the time for all good men to come to the aid of their nation.' }"> <MvEVAL EXPR="{ Replace(g.string, 'nation', 'country', g.start) }"><br> <MvEVAL EXPR="{ g.start }"> </MvCOMMENT><MvASSIGNNAME="l.savestring"VALUE="{ l.string }>"<MvIFEXPR="{ l.start LT 1 }>"<MvASSIGNNAME="l.start"VALUE="{ 1 }>"</MvIF><MvIFEXPR="{ l.start GT 1 }>"<MvASSIGNNAME="l.left"VALUE="{ substring(l.string,1,l.start -1) }>"</MvIF><MvASSIGNNAME="l.string"VALUE="{ substring(l.string,l.start,len(l.string)) }>"<MvASSIGNNAME="l.posn"VALUE="{ l.search IN l.string }>"<MvIFEXPR="{ l.posn GT 1 }>"<MvASSIGNNAME="l.left"VALUE="{ l.left $ substring(l.string,1,(l.posn -1)) }>"<MvASSIGNNAME="l.string"VALUE="{ substring(l.string,l.posn,len(l.string)) }>"</MvIF><MvIFEXPR="{ (l.search IN l.string ) EQ 1 }>"<MvASSIGNNAME="l.right"VALUE="{ substring(l.string,len(l.search)+1,len(l.string)) }>"<MvASSIGNNAME="l.start"VALUE="{ len(l.left $ l.replace) + 1 }>"<MvASSIGNNAME="l.return"VALUE="{ l.left $ l.replace $ l.right }>"<MvIFEXPR="{ l.start GT len(l.return) }>"<MvASSIGNNAME="l.start"VALUE="{ 0 }>"</MvIF><MvELSE><MvASSIGNNAME="l.return"VALUE="{ l.savestring }>"<MvASSIGNNAME="l.start"VALUE="{ 0 }>"</MvIF><MvFUNCRETURNVALUE="{ l.return }>"</MvFUNCTION>