toguid()

Converts a string to a guid scalar.

Note

If you have a hard-coded guid, we recommend using guid().

Syntax

toguid(Expr)

Arguments

  • Expr: Expression that will be converted to guid scalar.

Returns

The conversion process takes the first 32 characters of the input, ignoring properly located hyphens, validates that the characters are between 0-9 or a-f, and then converts the string into a guid scalar. The rest of the string is ignored.

  • If the conversion is successful, the result will be a guid scalar.
  • Otherwise, the result will be null.

Examples

datatable(str: string)
[
    "0123456789abcdef0123456789abcdef",
    "0123456789ab-cdef-0123-456789abcdef",
    "a string that is not a guid"
]
| extend guid = toguid(str)

Output:

str guid
0123456789abcdef0123456789abcdef 01234567-89ab-cdef-0123-456789abcdef
0123456789ab-cdef-0123-456789abcdef 01234567-89ab-cdef-0123-456789abcdef
a string that is not a guid