Pattern.Split 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| 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
要拆分的字元序列
傳回
透過將輸入分割至與此模式匹配而得出的字串陣列
- 屬性
備註
將給定的輸入序列分割成與此模式匹配的部分。
此方法的運作方式類似於透過呼叫兩參數 #split(java.lang.CharSequence, int) split 方法,輸入序列為零,且極限參數為零。 因此,後方的空字串不會包含在結果陣列中。
"boo:and:foo"例如,輸入 ,使用這些表達式會得到以下結果:
<table class=“plain” style=“margin-left:2em”>caption style=“display:none”>分割範例顯示正則表達式與結果</caption<>thead<>tr><th scope=“col”>Regex</th<>th scope=“col”>Result</th<><>/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 文件 java.util.regex.Pattern.split(java.lang.CharSequence)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
適用於
Split(String)
將給定的輸入序列分割成與此模式匹配的部分。
public string[] Split(string input);
member this.Split : string -> string[]
參數
- input
- String
要拆分的字元序列
傳回
透過將輸入分割至與此模式匹配而得出的字串陣列
備註
將給定的輸入序列分割成與此模式匹配的部分。
此方法的運作方式類似於透過呼叫兩參數 #split(java.lang.CharSequence, int) split 方法,輸入序列為零,且極限參數為零。 因此,後方的空字串不會包含在結果陣列中。
"boo:and:foo"例如,輸入 ,使用這些表達式會得到以下結果:
<table class=“plain” style=“margin-left:2em”>caption style=“display:none”>分割範例顯示正則表達式與結果</caption<>thead<>tr><th scope=“col”>Regex</th<>th scope=“col”>Result</th<><>/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 文件 java.util.regex.Pattern.split(java.lang.CharSequence)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
適用於
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
如上所述的結果閾值
傳回
透過將輸入分割至與此模式匹配而得出的字串陣列
- 屬性
備註
將給定的輸入序列分割成與此模式匹配的部分。
此方法回傳的陣列包含輸入序列中每個被與此模式相符的子序列終止,或在輸入序列結尾終止的子串。 陣列中的子字串依輸入中出現的順序排列。 若此模式與輸入的任何子序列不匹配,則所得陣列僅有一個元素,即字串形式的輸入序列。
當輸入序列開頭有正寬度匹配時,則在結果陣列的開頭包含一個空的前導子串。 然而,開頭的零寬度匹配只能產生該空的前導子字串,適用於執行或目標為 API 版本 <= 28 的應用程式。
參數 limit 控制該圖案被套用的次數,因此影響結果陣列的長度。
<烏爾><·李>
若極 限 為正,則該模式最多可應用於極 限 - 1 次時,陣列長度不會超過 極限,且陣列最後一個項目包含超過最後匹配分隔符的所有輸入。
</李>
<李>
若極 限 為零,則該模式會盡可能多次套用,陣列長度可任意,且後方空字串將被捨棄。
</李>
<李>
若極 限 為負,則該圖案將盡可能多次套用,陣列長度可任意。
</li></ul>
例如,輸入 "boo:and:foo"會得到以下參數的結果:
<table class=“plain” style=“margin-left:2em;”><caption style=“display:none”> 分割範例顯示正則表達式、limit 與 result</caption<>thead<>tr<>th scope=“col”>Regex</th<>scope = “col”Limit/th><th scope=“col”>>Result<</<>th<>/tbody><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><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 文件 java.util.regex.Pattern.split(java.lang.CharSequence, int)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
適用於
Split(String, Int32)
將給定的輸入序列分割成與此模式匹配的部分。
public string[] Split(string input, int limit);
member this.Split : string * int -> string[]
參數
- input
- String
要拆分的字元序列
- limit
- Int32
如上所述的結果閾值
傳回
透過將輸入分割至與此模式匹配而得出的字串陣列
備註
將給定的輸入序列分割成與此模式匹配的部分。
此方法回傳的陣列包含輸入序列中每個被與此模式相符的子序列終止,或在輸入序列結尾終止的子串。 陣列中的子字串依輸入中出現的順序排列。 若此模式與輸入的任何子序列不匹配,則所得陣列僅有一個元素,即字串形式的輸入序列。
當輸入序列開頭有正寬度匹配時,則在結果陣列的開頭包含一個空的前導子串。 然而,開頭的零寬度匹配只能產生該空的前導子字串,適用於執行或目標為 API 版本 <= 28 的應用程式。
參數 limit 控制該圖案被套用的次數,因此影響結果陣列的長度。
<烏爾><·李>
若極 限 為正,則該模式最多可應用於極 限 - 1 次時,陣列長度不會超過 極限,且陣列最後一個項目包含超過最後匹配分隔符的所有輸入。
</李>
<李>
若極 限 為零,則該模式會盡可能多次套用,陣列長度可任意,且後方空字串將被捨棄。
</李>
<李>
若極 限 為負,則該圖案將盡可能多次套用,陣列長度可任意。
</li></ul>
例如,輸入 "boo:and:foo"會得到以下參數的結果:
<table class=“plain” style=“margin-left:2em;”><caption style=“display:none”> 分割範例顯示正則表達式、limit 與 result</caption<>thead<>tr<>th scope=“col”>Regex</th<>scope = “col”Limit/th><th scope=“col”>>Result<</<>th<>/tbody><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><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 文件 java.util.regex.Pattern.split(java.lang.CharSequence, int)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。