String splitting (Version: 2) - Miva - Snippets
<mvt:assign name="g.string" value="'one|two|three|four|five|six'" /> <h3>Split String mvt:do</h3> <p>Does not inherently support multi-character splitting, you'd have to perform a glosub first (see next example)</p> <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( g.string, '|', g.splitString )" /> <!-- @@ &mvt:global:MvDO_Error; --> <mvt:foreach iterator="line" array="global:splitString"> &mvt:line;</br> </mvt:foreach> <hr> <h3>Deserialize+Global Substitution</h3> <p>This method supports multi-character splitting, as you're just replacing your seperator with a single comma</p> <mvt:assign name="g.array" value="miva_array_deserialize( glosub(g.string,'|',',') )" /> <mvt:foreach iterator="line" array="global:array"> &mvt:line;</br> </mvt:foreach> <hr> <h3>Get Token</h3> <p>Doesn't support multi-character splitting, a little harder to read in my opinion</p> <mvt:assign name="" value="'|'" /> <mvt:assign name="l.count" value="1" /> <mvt:assign name="l.token" value="gettoken(g.string, , l.count)" /> <mvt:while expr="NOT ISNULL l.token"> <mvt:assign name="l.array_length" value="miva_array_insert( l.settings:my_array, l.token, -1 )" /> <mvt:assign name="l.count" value="l.count + 1" /> <mvt:assign name="l.token" value="gettoken(g.string, , l.count)" /> </mvt:while> <mvt:foreach iterator="row" array="my_array"> &mvt:row;</br> </mvt:foreach>