Udostępnij za pośrednictwem


Pattern.Split Method

Definition

Overloads

Split(ICharSequence)

Splits the given input sequence around matches of this pattern.

Split(String)

Splits the given input sequence around matches of this pattern.

Split(ICharSequence, Int32)

Splits the given input sequence around matches of this pattern.

Split(String, Int32)

Splits the given input sequence around matches of this pattern.

Split(ICharSequence)

Splits the given input sequence around matches of this pattern.

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

Parameters

input
ICharSequence

The character sequence to be split

Returns

String[]

The array of strings computed by splitting the input around matches of this pattern

Attributes

Remarks

Splits the given input sequence around matches of this pattern.

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

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

<table class="plain" style="margin-left:2em"> <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>

Java documentation for java.util.regex.Pattern.split(java.lang.CharSequence).

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

Split(String)

Splits the given input sequence around matches of this pattern.

public string[] Split (string input);
member this.Split : string -> string[]

Parameters

input
String

The character sequence to be split

Returns

String[]

The array of strings computed by splitting the input around matches of this pattern

Remarks

Splits the given input sequence around matches of this pattern.

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

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

<table class="plain" style="margin-left:2em"> <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>

Java documentation for java.util.regex.Pattern.split(java.lang.CharSequence).

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

Split(ICharSequence, Int32)

Splits the given input sequence around matches of this pattern.

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

Parameters

input
ICharSequence

The character sequence to be split

limit
Int32

The result threshold, as described above

Returns

String[]

The array of strings computed by splitting the input around matches of this pattern

Attributes

Remarks

Splits the given input sequence around matches of this pattern.

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

When there is a positive-width match at the beginning of the input sequence then an empty leading substring is included at the beginning of the resulting array. A zero-width match at the beginning however can only produce such an empty leading substring for apps running on or targeting API versions <= 28.

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 input "boo:and:foo", for example, yields the following results with these parameters:

<table class="plain" style="margin-left:2em;"> <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>

Java documentation for java.util.regex.Pattern.split(java.lang.CharSequence, 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

Split(String, Int32)

Splits the given input sequence around matches of this pattern.

public string[] Split (string input, int limit);
member this.Split : string * int -> string[]

Parameters

input
String

The character sequence to be split

limit
Int32

The result threshold, as described above

Returns

String[]

The array of strings computed by splitting the input around matches of this pattern

Remarks

Splits the given input sequence around matches of this pattern.

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

When there is a positive-width match at the beginning of the input sequence then an empty leading substring is included at the beginning of the resulting array. A zero-width match at the beginning however can only produce such an empty leading substring for apps running on or targeting API versions <= 28.

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 input "boo:and:foo", for example, yields the following results with these parameters:

<table class="plain" style="margin-left:2em;"> <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>

Java documentation for java.util.regex.Pattern.split(java.lang.CharSequence, 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