Pattern.Split 方法

定义

重载

Split(ICharSequence)

围绕此模式的匹配项拆分给定的输入序列。

Split(String)

围绕此模式的匹配项拆分给定的输入序列。

Split(ICharSequence, Int32)

围绕此模式的匹配项拆分给定的输入序列。

Split(String, Int32)

围绕此模式的匹配项拆分给定的输入序列。

Split(ICharSequence)

围绕此模式的匹配项拆分给定的输入序列。

[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[]

参数

input
ICharSequence

要拆分的字符序列

返回

String[]

通过拆分此模式匹配项的输入来计算的字符串数组

属性

注解

围绕此模式的匹配项拆分给定的输入序列。

此方法的工作原理是使用给定输入序列调用双参数 #split(java.lang.CharSequence, int) split 方法和限制参数为零。 因此,生成的数组中不包括尾随空字符串。

"boo:and:foo"例如,输入使用以下表达式生成以下结果:

<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<>scope=“col”>Result</th></tr></thead><tbody><tr><th scope=“row” style=“text-weight:normal”>:</th><td}</td>><{ "boo", "and", "foo"/tr><tr><th scope=“row”<style=“text-weight:normal”>o</th><td}</td><>{ "b", "", ":and:f"/tr></tbody></table>

适用于 . 的 java.util.regex.Pattern.split(java.lang.CharSequence)Java 文档

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于

Split(String)

围绕此模式的匹配项拆分给定的输入序列。

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

参数

input
String

要拆分的字符序列

返回

String[]

通过拆分此模式匹配项的输入来计算的字符串数组

注解

围绕此模式的匹配项拆分给定的输入序列。

此方法的工作原理是使用给定输入序列调用双参数 #split(java.lang.CharSequence, int) split 方法和限制参数为零。 因此,生成的数组中不包括尾随空字符串。

"boo:and:foo"例如,输入使用以下表达式生成以下结果:

<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<>scope=“col”>Result</th></tr></thead><tbody><tr><th scope=“row” style=“text-weight:normal”>:</th><td}</td>><{ "boo", "and", "foo"/tr><tr><th scope=“row”<style=“text-weight:normal”>o</th><td}</td><>{ "b", "", ":and:f"/tr></tbody></table>

适用于 . 的 java.util.regex.Pattern.split(java.lang.CharSequence)Java 文档

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于

Split(ICharSequence, Int32)

围绕此模式的匹配项拆分给定的输入序列。

[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[]

参数

input
ICharSequence

要拆分的字符序列

limit
Int32

结果阈值,如上所述

返回

String[]

通过拆分此模式匹配项的输入来计算的字符串数组

属性

注解

围绕此模式的匹配项拆分给定的输入序列。

此方法返回的数组包含输入序列的每个子字符串,这些子字符串由与此模式匹配的另一个子序列终止,或者由输入序列的末尾终止。 数组中的子字符串按输入中出现的顺序。 如果此模式与输入的任何子序列不匹配,则生成的数组只有一个元素,即字符串形式的输入序列。

当输入序列的开头有正宽度匹配时,生成的数组的开头将包含一个空前导子字符串。 但是,开头的零宽度匹配只能为运行或面向 API 版本 <= 28 的应用生成如此空的前导子字符串。

参数 limit 控制应用模式的次数,因此会影响生成的数组的长度。 <ul><li>

如果限制为正值,则模式将应用于最多限制 限制,并且数组的最后一个条目将包含超出上次匹配分隔符的所有输入。

</李>

<李>

如果限制为零,则模式将尽可能多地应用,数组可以具有任何长度,并且将丢弃尾随空字符串。

</李>

<李>

如果限制为负数,则模式将应用尽可能多的时间,并且数组可以具有任何长度。

</li></ul>

"boo:and:foo"例如,输入使用以下参数生成以下结果:

<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 scope=“col”>Limit</th><scope=“col”>Result</th></tr<>/thead><tbody><tr><th scope=“row” rowspan=“3” style=“font-weight:normal”>:</th><scope=“row” style=“font-weight:normal; text-align:right;padding-right:1em“>2/th<>td}</td{ "boo", "and:foo">></tr><><--: --<>th scope=”row“ style=”font-weight:normal; text-align:right; padding-right:1em“>5</th<>td}</td>><{ "boo", "and", "foo"/tr>><<--: --<>th scope=”row“ style=”font-weight:normal; text-align:right; padding-right:1em“>-2</th><td}</td><{ "boo", "and", "foo">/tr tr><><<th scope=“row” rowspan=“3” style=“font-weight:normal”o/th<>scope=“row” style=“font-weight:normal; text-align:right; padding-right:1em”>5</th<>td}/td>><{ "b", "", ":and:f", "", ""/tr><tr><-- o --<>th scope=“row” style=“font-weight:normal; text-align:right; padding-right:1em”>-2</th><td}<</td><{ "b", "", ":and:f", "", "">/tr><><-- o --<><>th scope=“row” style=“font-weight:normal;text-align:right;padding-right:1em“>0/th><td}</td{ "b", "", ":and:f"><>/tr></tbody<>/table<>

适用于 . 的 java.util.regex.Pattern.split(java.lang.CharSequence, int)Java 文档

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于

Split(String, Int32)

围绕此模式的匹配项拆分给定的输入序列。

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

参数

input
String

要拆分的字符序列

limit
Int32

结果阈值,如上所述

返回

String[]

通过拆分此模式匹配项的输入来计算的字符串数组

注解

围绕此模式的匹配项拆分给定的输入序列。

此方法返回的数组包含输入序列的每个子字符串,这些子字符串由与此模式匹配的另一个子序列终止,或者由输入序列的末尾终止。 数组中的子字符串按输入中出现的顺序。 如果此模式与输入的任何子序列不匹配,则生成的数组只有一个元素,即字符串形式的输入序列。

当输入序列的开头有正宽度匹配时,生成的数组的开头将包含一个空前导子字符串。 但是,开头的零宽度匹配只能为运行或面向 API 版本 <= 28 的应用生成如此空的前导子字符串。

参数 limit 控制应用模式的次数,因此会影响生成的数组的长度。 <ul><li>

如果限制为正值,则模式将应用于最多限制 限制,并且数组的最后一个条目将包含超出上次匹配分隔符的所有输入。

</李>

<李>

如果限制为零,则模式将尽可能多地应用,数组可以具有任何长度,并且将丢弃尾随空字符串。

</李>

<李>

如果限制为负数,则模式将应用尽可能多的时间,并且数组可以具有任何长度。

</li></ul>

"boo:and:foo"例如,输入使用以下参数生成以下结果:

<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 scope=“col”>Limit</th><scope=“col”>Result</th></tr<>/thead><tbody><tr><th scope=“row” rowspan=“3” style=“font-weight:normal”>:</th><scope=“row” style=“font-weight:normal; text-align:right;padding-right:1em“>2/th<>td}</td{ "boo", "and:foo">></tr><><--: --<>th scope=”row“ style=”font-weight:normal; text-align:right; padding-right:1em“>5</th<>td}</td>><{ "boo", "and", "foo"/tr>><<--: --<>th scope=”row“ style=”font-weight:normal; text-align:right; padding-right:1em“>-2</th><td}</td><{ "boo", "and", "foo">/tr tr><><<th scope=“row” rowspan=“3” style=“font-weight:normal”o/th<>scope=“row” style=“font-weight:normal; text-align:right; padding-right:1em”>5</th<>td}/td>><{ "b", "", ":and:f", "", ""/tr><tr><-- o --<>th scope=“row” style=“font-weight:normal; text-align:right; padding-right:1em”>-2</th><td}<</td><{ "b", "", ":and:f", "", "">/tr><><-- o --<><>th scope=“row” style=“font-weight:normal;text-align:right;padding-right:1em“>0/th><td}</td{ "b", "", ":and:f"><>/tr></tbody<>/table<>

适用于 . 的 java.util.regex.Pattern.split(java.lang.CharSequence, int)Java 文档

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于