Vitali Plagov
05/10/2022, 7:12 PM"abc".split("")
splits into a list of Strings [, a, b, c, ]
(5 elements) with an empty string at the beginning and end. Why is it so? And how to split the string into individual letters to the List<String>?Vampire
05/10/2022, 7:21 PM"abc".chunked(1)
ephemient
05/10/2022, 7:23 PM"abc".toList() == listOf('a', 'b', 'c')
"abc".map { it.toString(0 } = listOf("a", "b", "c")
(or chunked(1)
as mentioned)ephemient
05/10/2022, 7:24 PMephemient
05/10/2022, 7:25 PM("abc" as java.lang.String).split("".toRegex().toPattern()) == listOf("a", "b", "c", "") // current versions of Java (it has changed!)
"abc".split("".toRegex()) == listOf("", "a", "b", "c", "") // Kotlin
Vitali Plagov
05/10/2022, 7:25 PMtoList()
returns list of Chars. But chunked(1)
is exactly what I need. Thanks guys!Amarnadh
05/10/2022, 8:03 PMVampire
05/10/2022, 8:07 PMKlitos Kyriacou
05/11/2022, 9:06 AM["", "", ... "", "a", "", "", ..., "", "b",...]
so why the arbitrary decision of assuming there is just one empty string between each character? You could just as well say there is 0 empty strings between each character (since that is another valid arbitrary choice of the valid range of 0 to infinity).Vampire
05/11/2022, 9:14 AMephemient
05/11/2022, 9:18 AMMichael de Kaste
05/11/2022, 9:30 AMassert(string.size > 0)
on that bad boy and call it a day. Can't have inconsistency if it can't even be. taps foreheadVampire
05/11/2022, 9:33 AMVampire
05/11/2022, 9:33 AM(?i)
Klitos Kyriacou
05/11/2022, 9:48 AMVampire
05/11/2022, 9:51 AM