码迷,mamicode.com
首页 > 其他好文 > 详细

String.split(String regex, int limit)

时间:2015-08-27 15:33:26      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:


public String[] split(String regex, int limit)


limit n 大于0,则pattern(模式)应用n - 1 次
关于String.split(String regex, int limit)String s = “boo:and:foo”
关于String.split(String regex, int limit)s.split(“:”,2)
关于String.split(String regex, int limit)//result is { “boo”, “and:foo” }
limit n 小于0,则pattern(模式)应用无限次
关于String.split(String regex, int limit)String s = “boo:and:foo”
关于String.split(String regex, int limit)s.split(“:”,-2)
关于String.split(String regex, int limit)//result is { “boo”, “and”, “foo” }
limit n 等于0,则pattern(模式)应用无限次并且省略末尾的空字串
关于String.split(String regex, int limit)String s = “boo:and:foo”
关于String.split(String regex, int limit)s.split(“o”, -2)
//result is { “b”, “”, “and:f”, “”, “” }
s.split(“o”, 0)
//result is { “b”, “”, “and:f” }
例子:string “boo:and:foo”
Regex Limit Result
2 { “boo”, “and:foo” }
5 { “boo”, “and”, “foo” }
-2 { “boo”, “and”, “foo” }
o 5 { “b”, “”, “:and:f”, “”, “” }
o -2 { “b”, “”, “:and:f”, “”, “” }
o 0 { “b”, “”, “:and:f” }


String.split(String regex, int limit)

标签:

原文地址:http://my.oschina.net/u/1257052/blog/497950

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!