A much faster way to get do last index of (Posted By Kent Multer on the forum)
<MvFUNCTION NAME = "FinalIndexof" PARAMETERS = "target var, search" STANDARDOUTPUTLEVEL = "">
<MvFUNCTIONRETURN VALUE = "{ len(l.target) - len(gettoken(l.target, l.search, (len(l.target) - len(glosub(l.target, l.search, ''))) + 1)) }">
</MvFUNCTION>
The indexof() and indexofi() functions make parcing strings much more efficient when you must search for multiple occurances of the same string; For example when search for starting and ending double quotes or paired markers like ( and ).
The function below last_indexof() finds the last occurance of the string '/'
<MvASSIGN NAME = "g.url" VALUE = "https://www.mivascript.com/mm5/merchant.mvc">
<MvASSIGN NAME = "l.pos" VALUE = "{ last_indexof('/', g.url) }">
<MvASSIGN NAME = "l.filename" VALUE = "{ substring(g.url, l.pos+1, len(g.url)) }">
<MvEVAL EXPR = "{ l.filename }">
<MvEXIT>
<MvFUNCTION NAME = "last_indexof" PARAMETERS = "search,target" STANDARDOUTPUTLEVEL = "">
<MvASSIGN NAME = "l.length" VALUE = "{ len(l.target) }">
<MvCOMMENT> Find the first occurance </MvCOMMENT>
<MvASSIGN NAME = "l.posL" VALUE = "{ l.search IN l.target }">
<MvASSIGN NAME = "l.posR" VALUE = "{ l.posL }">
<MvASSIGN NAME = "l.posN" VALUE = "{ l.posL + len(l.search) }">
<MvWHILE EXPR = "{ l.posN AND (l.posN LE l.length) }">
<MvCOMMENT> Find the last occurance </MvCOMMENT>
<MvASSIGN NAME = "l.posN" VALUE = "{ indexof(l.search, l.target, l.posR + len(l.search)) }">
<MvIF EXPR = "{ l.posN }">
<MvASSIGN NAME = "l.posR" VALUE = "{ l.posN }">
</MvIF>
</MvWHILE>
<MvFUNCTIONRETURN VALUE = "{ l.posR }">
</MvFUNCTION>