Search code examples
azureazure-data-explorer

Kusto query language split @ character and take last item


If I have a string for example: "this.is.a.string.and.I.need.the.last.part" I am trying to get the last part of the string after the last ".", which in this case is "part" How to I achieve this? One way I tried was to split the string on ".", I get a array back, but then I don't know how to retrieve the last item in the array.

| extend ToSplitstring = split("this.is.a.string.and.I.need.the.last.part", ".") 

gives me:

["this", "is","a","string","and","I","need","the","last", "part"]

and a second try I have tried this:

| extend ToSubstring = substring(myString, lastindexof(myString, ".")+1)

but Kusto do not have a function of lastindexof.

Anyone with tips?


Solution

  • you can access the last member of the array using a negative index -1.

    e.g. this:

    print split("this.is.a.string.and.I.need.the.last.part", ".")[-1]

    returns a single table, with a single column and a single record, with the value part