07/13/2022, 6:31 PM
Is There a Best Way to Chunk a String from the last element to first Is there a good or best way to add some leading zeros for the string chunk that don't have an appropriate number of digits. At the code below I want to split a string where each chunk is composed of 4 digits. To add some leading zeros to a string I use this approach: val text = "1010111".reversed() // 1110101 | len: 7 .chunked(4) { // [1110, 101 *this element only gets 3 digits] val sb = StringBuilder(it) val rem = it.length % 4 /* [1110, 1010 -> now this element have a same...