标签:span 字符串 split 位置 -- es6 cal string ring
split()函数:
def split(arg0: String): Array[String]
def split(arg0: String, arg1: Int): Array[String]
scala> "a-b-c-d-e".split("-",3)
res0: Array[String] = Array(a, b, c-d-e)
scala> "a-b-c-d-e".split("-",4)
res1: Array[String] = Array(a, b, c, d-e)
scala> "a-b-c-d-e".split("-",5)
res2: Array[String] = Array(a, b, c, d, e)
scala> "a-b-c-d-e".split("-",6)
res3: Array[String] = Array(a, b, c, d, e)
scala> "a-b-c-d-e".split("-")
res6: Array[String] = Array(a, b, c, d, e)
scala> "a-b-c-d--e---".split("-")
res7: Array[String] = Array(a, b, c, d, "", e)
//arg1=0,split函数尽可能多的匹配arg0,不保留处于末尾位置的空字符串,空字符串例外。比如:
scala> "--a-b-c-d--e---".split("-")
res8: Array[String] = Array("", "", a, b, c, d, "", e)
scala> "".split("-",0)
res1: Array[String] = Array("")
//arg1<0,保留末尾的空字符串
scala> "--a-b-c-d--e---".split("-",-1)
res0: Array[String] = Array("", "", a, b, c, d, "", e, "", "", "")
标签:span 字符串 split 位置 -- es6 cal string ring
原文地址:http://www.cnblogs.com/fulse/p/7855939.html