Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* levelezősök
  + Adator. prog.
  + feladatsor
  + quick link

teaching assets


Félévek

* 2024/25/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

split / join

#############################

Let's see the equivalent of Python's split and join.

Join

In Scala it's called mkString.

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

Split

scala> 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)
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2018 February 15, 16:25