Verified Commit cd4b7fc4 authored by AtjonTV's avatar AtjonTV

extensions: String.splitBy every num chars

parent 72bd5532
......@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- FFDB (FlatFile DataBase) (`klib.ffdb.FFDB`)
- IncompatibleDatabaseException (`klib.exceptions.IncompatibleDatabaseException`)
- `openFFDB` extension for String
- `splitBy` extension for String
### Changed
- Upgraded Kotlin from 1.3.61 to 1.3.70
### Deprecated
......
......@@ -428,3 +428,20 @@ infix fun String?.asLongOr(or: Int): Long {
*/
@OptIn(Experimental::class)
fun String.openFFDB(version: FFDB.Version = FFDB.Version.V2) = FFDB.open(this, version.version)
/**
* Split string every num characters
*
* @param num The number of chars to split after
*
* @since 5.0.0
* @author Thomas Obernosterer
*/
fun String.splitBy(num: Int = 1): List<String> {
val list: MutableList<String> = ArrayList()
for (i in num until length step num)
list.add(substring(i - num, i))
return list
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment