kotlin.text.singleOrNull

singleOrNull

fun CharSequence.singleOrNull(): Char?

Returns single character, or null if the char sequence is empty or has more than one character.

inline fun CharSequence.singleOrNull(
    predicate: (Char) -> Boolean
): Char?

Returns the single character matching the given predicate, or null if character was not found or more than one character was found.