obviously to split can be used to break a string in to sub-strings at specific character or delimiter string, but i was looking for any easy way to break into fixed length sub-strings. eg.
"abcde".splitAt(2) == listOf("ab", "cd", "e")
any ideas?
obviously to split can be used to break a string in to sub-strings at specific character or delimiter string, but i was looking for any easy way to break into fixed length sub-strings. eg.
"abcde".splitAt(2) == listOf("ab", "cd", "e")
any ideas?
Use the CharSequence.chunked(size: Int) function. It does exactly that:
println("abcde".chunked(2)) // [ab, cd, e]