sannysanoff
08/15/2017, 3:40 PMleonardootto
08/19/2017, 4:46 AMleonardootto
08/19/2017, 4:46 AMdean
08/19/2017, 7:19 AM// might want some error checking
fun String.truncate(maxLen: Int): String =
if (this.length < maxLen) this else this.take(maxLen-3) + "..."
You can then use
"short".truncate(10) // "short"
"wowthisislong".truncate(10) // "wowthis..."