Last active
May 8, 2019 21:27
-
-
Save matteo-grella/b6db6fd8aad44901fc2d8ef147ccfc75 to your computer and use it in GitHub Desktop.
Split text into substrings of N characters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Split text into substrings of [size] characters. | |
* | |
* @param size the split size. | |
* @return an array of the split text. | |
*/ | |
private fun String.splitToNChar(size: Int): List<String> { | |
val parts = ArrayList<String>() | |
val length = this.length | |
var i = 0 | |
while (i < length) { | |
parts.add(this.substring(i, Math.min(length, i + size))) | |
i += size | |
} | |
return parts | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment