substring()

 
Returns the substring of string, beginning at position start, length characters long.
Syntax
substring( string, position, length )
User Annotations: substring
Ray Yates : mivascript at, pcinet d0t com
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.
<MvFUNCTION NAME = "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>
    
    <MvASSIGN NAME = "l.savestring" VALUE = "{ l.string }">
    <MvIF EXPR = "{ l.start LT 1 }">
        <MvASSIGN NAME = "l.start" VALUE = "{ 1 }">
    </MvIF>

    <MvIF EXPR = "{ l.start GT 1 }">
        <MvASSIGN NAME = "l.left" VALUE = "{ substring(l.string,1,l.start -1) }">
    </MvIF>
    <MvASSIGN NAME = "l.string" VALUE = "{ substring(l.string,l.start,len(l.string)) }">

    <MvASSIGN NAME = "l.posn" VALUE = "{ l.search IN l.string }">
    <MvIF EXPR = "{ l.posn GT 1 }">
        <MvASSIGN NAME = "l.left" VALUE = "{ l.left $ substring(l.string,1,(l.posn -1)) }">
        <MvASSIGN NAME = "l.string" VALUE = "{ substring(l.string,l.posn,len(l.string)) }">
    </MvIF>

     <MvIF EXPR = "{ (l.search IN l.string ) EQ 1 }">
        <MvASSIGN NAME = "l.right" VALUE = "{ substring(l.string,len(l.search)+1,len(l.string)) }">
        <MvASSIGN NAME = "l.start" VALUE = "{ len(l.left $ l.replace) + 1 }">
        <MvASSIGN NAME = "l.return" VALUE = "{  l.left $ l.replace $ l.right }">
        <MvIF EXPR = "{ l.start GT len(l.return) }">
            <MvASSIGN NAME = "l.start" VALUE = "{ 0 }">
        </MvIF>
    <MvELSE>
        <MvASSIGN NAME = "l.return" VALUE = "{ l.savestring }">
        <MvASSIGN NAME = "l.start" VALUE = "{ 0 }">
    </MvIF>

    <MvFUNCRETURN VALUE = "{ l.return }">
</MvFUNCTION>