Announcement

Collapse
No announcement yet.

SplitString does not completely overwrite an existing array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SplitString does not completely overwrite an existing array

    I was surprised to learn that creating arrays from strings using SplitString does not completely overwrite an existing array.

    This became an issue when I used SplitString to create arrays of various sizes in a loop.

    Here is a simplified example...
    HTML Code:
    <mvt:assign name="l.myStringA" value=" 'red|yellow|blue' " />
    <mvt:assign name="l.myStringB" value=" 'dog|cat|horse|mouse|rabbit' " />
    <mvt:assign name="l.myStringC" value=" 'sweet|sour' " />
    
    <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( l.myStringA, '|', l.settings:myArray )"/>
    <mvt:foreach iterator="curNode" array="myArray" >
    [&mvt:curNode;]
    </mvt:foreach>
    
    <br />
    
    <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( l.myStringB, '|', l.settings:myArray )"/>
    <mvt:foreach iterator="curNode" array="myArray" >
    [&mvt:curNode;]
    </mvt:foreach>
    
    <br />
    
    <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( l.myStringC, '|', l.settings:myArray )"/>
    <mvt:foreach iterator="curNode" array="myArray" >
    [&mvt:curNode;]
    </mvt:foreach>

    Would output...
    Code:
    [red] [yellow] [blue]
    [dog] [cat] [horse] [mouse] [rabbit]
    [sweet] [sour] [horse] [mouse] [rabbit]

    To avoid this issue, I simply overwrite the variable "myArray" before each SplitString.
Working...
X