Do you need characters?
"Test".toList // Makes a list of characters "Test".toArray // Makes an array of characters
Do you need bytes?
"Test".getBytes // Java provides this
Do you need strings?
"Test".map(_.toString) // Vector of strings "Test".sliding(1).toList // List of strings "Test".sliding(1).toArray // Array of strings
Do you need UTF-32 code points? Ok, this is tougher.
def UTF32point(s: String, idx: Int = 0, found: List[Int] = Nil): List[Int] = { if (idx >= s.length) found.reverse else { val point = s.codePointAt(idx) UTF32point(s, idx + java.lang.Character.charCount(point), point :: found) } } UTF32point("Test")
Rex Kerr Feb 20 2018-11-11T00: 00Z
source share