String.split(String regex, int limit)

佐手、 提交于 2020-03-02 08:02:36

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” }


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!