substringWithinBounds

fun CharSequence.substringWithinBounds(startIndex: Int, endIndex: Int): String

Return

a substring of this string from startIndex to endIndex if the indices are within bounds. If startIndex is less than 0, the actual start index is 0. If endIndex is greater than the length of the string or less than the start index, the actual end index is the length of the string.