getOrElse

inline fun String.getOrElse(indices: IntRange, defaultValue: () -> String): String

Returns the substring from the given range if exist otherwise return else block.

Example:

"Hello".getOrElse(1..3) { "Hi" } // ell
"Hello".getOrElse(1..5) { "Hi" } // Hi

Since

1.1.0

See also

substring
IntRange

inline fun String.getOrElse(indices: IntProgression, defaultValue: () -> String): String

Returns the substring from the given progression if exist otherwise return else block.

Example:

"Hello".getOrElse(0..4 step 2) { "Hi" } // Hlo
"Hello".getOrElse(0..8 step 2) { "Hi" } // Hi

Since

1.1.0

See also

substring
IntProgression