truncateWords

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

Truncates a String at the nearest word boundary within maxLength. Example: "Hello beautiful world".truncateWords(14) → "Hello..."