getOrNull

fun String.getOrNull(indices: IntRange): String?

Returns the substring from the given range if exist otherwise return a null.

Example:

"Hello".getOrNull(1..3) // ell
"Hello".getOrNull(1..5) // null

Since

1.1.0

See also

substring
IntRange

fun String.getOrNull(indices: IntProgression): String?

Returns the substring from the given progression if exist otherwise return a null.

Example:

"Hello".getOrNull(0..4 step 2) // Hlo
"Hello".getOrNull(0..8 step 2) // null

Since

1.1.0

See also

substring
IntProgression