I'm just starting kotlin so I'm sure there is an easy way to do this but I don't see it. I want to split a into single-length sub strings using codepoints. In Java 8, this works:
public class UtfSplit {
static String [] utf8Split (String str) {
int [] codepoints = str.codePoints().toArray();
String [] rv = new String[codepoints.length];
for (int i = 0; i < codepoints.length; i++)
rv[i] = new String(codepoints, i, 1);
return rv;
}
public static void main(String [] args) {
String test = "こんにちは皆さん";
System.out.println("Test string:" + test);
StringBuilder sb = new StringBuilder("Result:");
for(String s : utf8Split(test))
sb.append(s).append(", ");
System.out.println(sb.toString());
}
}
Output is:
Test string:こんにちは皆さん
Result:こ, ん, に, ち, は, 皆, さ, ん,
How would I do this in kotlin?? I can get to codepoints although it's clumsy and I'm sure I'm doing it wrong. But I can't get from the codepoints back to a strings. The whole string/character interface seems different to me and I'm just not getting it.
Thanks Steve S.