String.Split Method

Definition

Overloads

Split(String)

Splits this string around matches of the given regular expression.

Split(String, Int32)

Splits this string around matches of the given regular expression.

Split(String)

Splits this string around matches of the given regular expression.

[Android.Runtime.Register("split", "(Ljava/lang/String;)[Ljava/lang/String;", "")]
public string[] Split (string regex);
[<Android.Runtime.Register("split", "(Ljava/lang/String;)[Ljava/lang/String;", "")>]
member this.Split : string -> string[]

Parameters

regex
String

the delimiting regular expression

Returns

String[]

the array of strings computed by splitting this string around matches of the given regular expression

Attributes

Exceptions

if regularExpression == null

Remarks

Splits this string around matches of the given regular expression.

This method works as if by invoking the two-argument #split(String, int) split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

The string "boo:and:foo", for example, yields the following results with these expressions:

<blockquote><table class="plain"> <caption style="display:none">Split examples showing regex and result</caption> <thead> <tr> <th scope="col">Regex</th> <th scope="col">Result</th> </tr> </thead> <tbody> <tr><th scope="row" style="text-weight:normal">:</th> <td>{ "boo", "and", "foo"}</td></tr> <tr><th scope="row" style="text-weight:normal">o</th> <td>{ "b", "", ":and:f"}</td></tr> </tbody> </table></blockquote>

Added in 1.4.

Java documentation for java.lang.String.split(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Split(String, Int32)

Splits this string around matches of the given regular expression.

[Android.Runtime.Register("split", "(Ljava/lang/String;I)[Ljava/lang/String;", "")]
public string[] Split (string regex, int limit);
[<Android.Runtime.Register("split", "(Ljava/lang/String;I)[Ljava/lang/String;", "")>]
member this.Split : string * int -> string[]

Parameters

regex
String

the delimiting regular expression

limit
Int32

the result threshold, as described above

Returns

String[]

the array of strings computed by splitting this string around matches of the given regular expression

Attributes

Exceptions

if regularExpression == null

Remarks

Splits this string around matches of the given regular expression.

The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

When there is a positive-width match at the beginning of this string then an empty leading substring is included at the beginning of the resulting array. A zero-width match at the beginning however never produces such empty leading substring.

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. <ul> <li>

If the limit is positive then the pattern will be applied at most limit&nbsp;-&nbsp;1 times, the array's length will be no greater than limit, and the array's last entry will contain all input beyond the last matched delimiter.

</li>

<li>

If the limit is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

</li>

<li>

If the limit is negative then the pattern will be applied as many times as possible and the array can have any length.

</li> </ul>

The string "boo:and:foo", for example, yields the following results with these parameters:

<blockquote><table class="plain"> <caption style="display:none">Split example showing regex, limit, and result</caption> <thead> <tr> <th scope="col">Regex</th> <th scope="col">Limit</th> <th scope="col">Result</th> </tr> </thead> <tbody> <tr><th scope="row" rowspan="3" style="font-weight:normal">:</th> <th scope="row" style="font-weight:normal; text-align:right; padding-right:1em">2</th> <td>{ "boo", "and:foo"}</td></tr> <tr><!-- : --> <th scope="row" style="font-weight:normal; text-align:right; padding-right:1em">5</th> <td>{ "boo", "and", "foo"}</td></tr> <tr><!-- : --> <th scope="row" style="font-weight:normal; text-align:right; padding-right:1em">-2</th> <td>{ "boo", "and", "foo"}</td></tr> <tr><th scope="row" rowspan="3" style="font-weight:normal">o</th> <th scope="row" style="font-weight:normal; text-align:right; padding-right:1em">5</th> <td>{ "b", "", ":and:f", "", ""}</td></tr> <tr><!-- o --> <th scope="row" style="font-weight:normal; text-align:right; padding-right:1em">-2</th> <td>{ "b", "", ":and:f", "", ""}</td></tr> <tr><!-- o --> <th scope="row" style="font-weight:normal; text-align:right; padding-right:1em">0</th> <td>{ "b", "", ":and:f"}</td></tr> </tbody> </table></blockquote>

An invocation of this method of the form str.split(regex,&nbsp;n) yields the same result as the expression

<blockquote> {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile compile}(<i>regex</i>).{@link java.util.regex.Pattern#split(java.lang.CharSequence,int) split}(<i>str</i>,&nbsp;<i>n</i>) </blockquote>

Added in 1.4.

Java documentation for java.lang.String.split(java.lang.String, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to