Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
Scala /
split / join
Let's see the equivalent of Python's split and join. JoinIn Scala it's called scala> a res18: Array[Int] = Array(4, 5, 20) scala> a.mkString(", ") // join the elems and put a comma between them res19: String = 4, 5, 20 scala> a.mkString("<", ", ", ">") // start sign, separator, end sign res20: String = <4, 5, 20> scala> a.mkString // simply put them together (the separator is the empty string) res21: String = 4520 Splitscala> val s = "aa,bb,cc,dd" s: String = aa,bb,cc,dd scala> s.split(",") // take it apart at the commas res25: Array[String] = Array(aa, bb, cc, dd) // -------------------- scala> val words = "scala is a cool language" // several whitespaces between words words: String = scala is a cool language scala> words.split("\\s+") // split it up by the whitespaces res31: Array[String] = Array(scala, is, a, cool, language) |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |