Divide this string around of the coincidences of the given regular expression.
1 string.split
<string.split
pattern='pattern'
limit='limit'
>
<text /> !
</string.split>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Apattern | string | Regular expression which indicates the pattern by which you should divide the text, for example:
|
|||
Alimit | integer | The limit parameter controls the number of times which the pattern is applied therefore affects the length of the resulting array. If the limit n is greater than zero, then the pattern is applied to the n-1 times, the length of the array will not be greater than n, and the last entry of the array will contain all the entry beyond the last delimiter found. If n is not positive, then the pattern is applied as many times as possible the resulting array can have any length. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Etext | string | Text in which perform the search. |
Returns | |
---|---|
Type | Description |
string | The array of calculated strings resulting from dividing this string around the matches of the given regular expression. |
Exceptions
requires 1 arguments, received: ...
The entry parameter has not been specified.
See also
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#startsWith(java.lang.String,%20int)
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 :