truncate

fun String.truncate(maxLength: Int, ellipsis: String = "..."): String

Shortens this string to at most maxLength characters, replacing the removed tail with ellipsis.

Returns this string unchanged when it already fits. When maxLength is smaller than the length of ellipsis, the ellipsis itself is cut to fit. Returns an empty string when maxLength is zero or negative.