parseHexDashOrNull
Parses a uuid from the standard hex-and-dash string representation as described in Uuid.toHexDashString, returning null is a string has a different format.
This function is case-insensitive, and for a valid hexDashString, the following property holds:
val uuid = Uuid.parseHexDashOrNull(hexDashString)!!
assertEquals(uuid.toHexDashString(), hexDashString.lowercase())Content copied to clipboard
The standard textual representation of uuids, also known as hex-and-dash format, is specified by RFC 9562 section 4.
Since Kotlin
2.3Return
A uuid equivalent to the specified uuid string, or null, if the string does not conform the format.
Parameters
hexDashString
A string in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", where each 'x' is a hexadecimal digit, either lowercase or uppercase.
See also
Samples
import kotlin.test.*
import kotlin.time.Instant
import kotlin.uuid.*
fun main() {
//sampleStart
val uuid = Uuid.parseHexDashOrNull("550E8400-e29b-41d4-A716-446655440000") // case insensitive
println(uuid) // 550e8400-e29b-41d4-a716-446655440000
assertNull(Uuid.parseHexDashOrNull("550E8400/e29b/41d4/A716/446655440000"))
//sampleEnd
}