scala中的split方法

1.对split方法的细节观察

scala> val s = "eggs, milk, butter, Coco Puffs"
s: String = eggs, milk, butter, Coco Puffs

scala> s.split(",")
res9: Array[String] = Array(eggs, " milk", " butter", " Coco Puffs")//注意eggs和" milk"两者的不同

scala> val s1 = "eggs,milk,butter, Coco Puffs"
s1: String = eggs,milk,butter, Coco Puffs

scala> s1.split(",")
res10: Array[String] = Array(eggs, milk, butter, " Coco Puffs")//只有Coco Puffs用""括起来了

scala> val s = "eggs, milk, butter, Coco Puffs"
s: String = eggs, milk, butter, Coco Puffs

scala> s.split(",").map(_.trim)//trim方法-->去空格
res11: Array[String] = Array(eggs, milk, butter, Coco Puffs)