parseOrNull

fun parseOrNull(uuidString: String): Uuid?(source)

Parses a uuid from one of the supported string representations, returning null if it matches none of them.

This function supports parsing the standard hex-and-dash and the hexadecimal string representations. For details about the hex-and-dash format, refer to toHexDashString. If parsing only the hex-and-dash format is desired, use parseHexDashOrNull instead. For details about the hexadecimal format, refer to toHexString. If parsing only the hexadecimal format is desired, use parseHexOrNull instead.

Note that this function is case-insensitive, meaning both lowercase and uppercase hexadecimal digits are considered valid. Additionally, support for more uuid formats may be introduced in the future. Therefore, users should not rely on the rejection of formats not currently supported.

Since Kotlin

2.3

Return

A uuid equivalent to the specified uuid string, or null, if the string does not conform any of supported formats.

Parameters

uuidString

A string in one of the supported uuid formats.

See also

Samples

import kotlin.test.*
import kotlin.time.Instant
import kotlin.uuid.*

fun main() { 
   //sampleStart 
   // Parsing is case-insensitive
val uuid1 = Uuid.parseOrNull("550E8400-e29b-41d4-A716-446655440000") // hex-and-dash
val uuid2 = Uuid.parseOrNull("550e8400E29b41D4a716446655440000") // hexadecimal

println("uuid1 == uuid2 is ${uuid1 == uuid2}") // true
println(uuid1) // 550e8400-e29b-41d4-a716-446655440000
println(uuid2) // 550e8400-e29b-41d4-a716-446655440000

assertNull(Uuid.parseOrNull("I'm not a UUID, sorry")) 
   //sampleEnd
}