Divide this string around of the coincidences of the given regular expression.

1 string.split

<string.split
    pattern='pattern'
    limit='limit'
>
    <text /> !
</string.split>

Exceptions

requires 1 arguments, received: ...

The entry parameter has not been specified.

Example

Split of a string.

Copy
<xsql-script name='string_split'>
    <body>
        <set name='arr'><string.split pattern='\s'>this is a test</string.split></set>

        <println><variable.typeof><arr /></variable.typeof></println>

        <set name='arrsize'><sub><array.size name='arr' />1</sub></set>
        <for name='idx' start='0' end='#arrsize'>
            <do>
                <println><idx /> :  <array.get name='arr'><idx /></array.get> </println>
            </do>
        </for>
    </body>
</xsql-script>

Returns:

Copy
> java.util.ArrayList
> 0 :  this
> 1 :  is
> 2 :  a
> 3 :  test
Example

Split of a string with limit.

Copy
<xsql-script name='string_split_limit'>
   <body>
       <set name='arr'><string.split pattern='\\|' limit='3' >this|is|a|test</string.split></set>

       <set name='arrsize'><sub><array.size name='arr' />1</sub></set>
       <for name='idx' start='0' end='#arrsize'>
           <do>
               <println><idx /> :  <array.get name='arr'><idx /></array.get> </println>
           </do>
       </for>
   </body>

</xsql-script>

Returns:

Copy
> java.util.ArrayList
> 0 :  this
> 1 :  is


> 2 :  a|test

Note: All empty string at the end of a split operation is removed of the resulting array. For example, the code:

Copy
<xsql-script>
    <body>
        <set name='s'>
            <string>a0,a1,,,a4,a5,a6,,,</string>
        </set>
        <set name='p'>
            <string>,</string>
        </set>
        <set name='arr'>
            <string.split pattern='#p'><s /></string.split>
        </set>
        <set name='arrsize'><sub><array.size name='arr' />1</sub></set>
        <for name='idx' start='0' end='#arrsize'>
            <do>
                <println><idx /> :  <array.get name='arr'><idx /></array.get></println>
            </do>
        </for>
    </body>
</xsql-script>

Performs the following output:

Copy
0 :  a0
1 :  a1
2 :
3 :
4 :  a4
5 :  a5
6 :  a6

And not, as you might expect, the output:

Copy
0 :  a0
1 :  a1
2 :
3 :
4 :  a4
5 :  a5
6 :  a6
7 :
8 :
9 :