Skip to content

Instantly share code, notes, and snippets.

@stargt
Created March 28, 2019 13:09
Show Gist options
  • Save stargt/935f8c50f149fcfd25b0985a9b6b7639 to your computer and use it in GitHub Desktop.
Save stargt/935f8c50f149fcfd25b0985a9b6b7639 to your computer and use it in GitHub Desktop.
string.spacer.kt
/* Put space into string between chunks of same length */
fun String.spacer(unitLength: Int = Int.MAX_VALUE, spaceCharacter: String = " "): String = chunked(unitLength).joinToString(spaceCharacter)
/**
* e.g.
* "123456789012345678".spacer(4) => "1234 5678 9012 3456 78"
* "123456789012345678".spacer(4, "@") => "1234@5678@9012@3456@78"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment