Share via


TextUtils.Split Method

Definition

Overloads

Split(String, Pattern)

Splits a string on a pattern.

Split(String, String)

This method yields the same result as text.split(expression, -1) except that if text.isEmpty() then this method returns an empty array whereas "".split(expression, -1) would have returned an array with a single "".

Split(String, Pattern)

Splits a string on a pattern.

[Android.Runtime.Register("split", "(Ljava/lang/String;Ljava/util/regex/Pattern;)[Ljava/lang/String;", "")]
public static string[]? Split (string? text, Java.Util.Regex.Pattern? pattern);
[<Android.Runtime.Register("split", "(Ljava/lang/String;Ljava/util/regex/Pattern;)[Ljava/lang/String;", "")>]
static member Split : string * Java.Util.Regex.Pattern -> string[]

Parameters

text
String

the string to split

pattern
Pattern

the regular expression to match

Returns

String[]

an array of strings. The array will be empty if text is empty

Attributes

Exceptions

if expression or text is null

Remarks

Splits a string on a pattern. This method yields the same result as pattern.split(text, -1) except that if text.isEmpty() then this method returns an empty array whereas pattern.split("", -1) would have returned an array with a single "".

The -1 means that trailing empty Strings are not removed from the result; Note that whether a leading zero-width match can result in a leading "" depends on whether your app android.content.pm.ApplicationInfo#targetSdkVersion targets an SDK version<= 28; see Pattern#split(CharSequence, int).

Java documentation for android.text.TextUtils.split(java.lang.String, java.util.regex.Pattern).

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, String)

This method yields the same result as text.split(expression, -1) except that if text.isEmpty() then this method returns an empty array whereas "".split(expression, -1) would have returned an array with a single "".

[Android.Runtime.Register("split", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;", "")]
public static string[]? Split (string? text, string? expression);
[<Android.Runtime.Register("split", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;", "")>]
static member Split : string * string -> string[]

Parameters

text
String

the string to split

expression
String

the regular expression to match

Returns

String[]

an array of strings. The array will be empty if text is empty

Attributes

Exceptions

if expression or text is null

Remarks

This method yields the same result as text.split(expression, -1) except that if text.isEmpty() then this method returns an empty array whereas "".split(expression, -1) would have returned an array with a single "".

The -1 means that trailing empty Strings are not removed from the result; for example split("a,", "," ) returns {"a", ""}. Note that whether a leading zero-width match can result in a leading "" depends on whether your app android.content.pm.ApplicationInfo#targetSdkVersion targets an SDK version<= 28; see Pattern#split(CharSequence, int).

Java documentation for android.text.TextUtils.split(java.lang.String, 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.

Applies to