toNotBlankStringOrNull

@ExperimentalSinceKotoolsTypes(version = "4.3.1")
fun String.toNotBlankStringOrNull(): NotBlankString?

Returns this string as a NotBlankString, or returns null if this string is blank.

Here's some usage examples:

var result: NotBlankString? = "hello world".toNotBlankStringOrNull()
println(result) // hello world

result = " ".toNotBlankStringOrNull()
println(null) // null

You can use the toNotBlankStringOrThrow function for throwing an IllegalArgumentException instead of returning null when this string is blank.