Kusto 查询语言拆分@字符并取最后一项
Kusto query language split @ character and take last item
如果我有一个字符串,例如:
“this.is.a.string.and.I.need.the.last.part”
我试图在最后一个“。”之后获取字符串的最后一部分,在这种情况下是“部分”
我如何实现这一目标?
我尝试的一种方法是在“.”上拆分字符串,我得到了一个数组,但是我不知道如何检索数组中的最后一项。
| extend ToSplitstring = split("this.is.a.string.and.I.need.the.last.part", ".")
给我:
["this", "is","a","string","and","I","need","the","last", "part"]
再试一次 我试过这个:
| extend ToSubstring = substring(myString, lastindexof(myString, ".")+1)
但是Kusto没有lastindexof的功能。
有人有提示吗?
您可以尝试下面的代码,并根据您的需要随意更改它:
let lastIndexof = (input:string, lookup: string) {
indexof(input, lookup, 0, -1, countof(input,lookup))
};
your_table_name
| extend ToSubstring = substring("this.is.a.string.and.I.need.the.last.part", lastIndexof("this.is.a.string.and.I.need.the.last.part", ".")+1)
您可以使用负索引访问数组的最后一个成员 -1
。
例如这个:
print split("this.is.a.string.and.I.need.the.last.part", ".")[-1]
returns 单个 table,具有单个列和单个记录,值为 part
如果我有一个字符串,例如: “this.is.a.string.and.I.need.the.last.part” 我试图在最后一个“。”之后获取字符串的最后一部分,在这种情况下是“部分” 我如何实现这一目标? 我尝试的一种方法是在“.”上拆分字符串,我得到了一个数组,但是我不知道如何检索数组中的最后一项。
| extend ToSplitstring = split("this.is.a.string.and.I.need.the.last.part", ".")
给我:
["this", "is","a","string","and","I","need","the","last", "part"]
再试一次 我试过这个:
| extend ToSubstring = substring(myString, lastindexof(myString, ".")+1)
但是Kusto没有lastindexof的功能。
有人有提示吗?
您可以尝试下面的代码,并根据您的需要随意更改它:
let lastIndexof = (input:string, lookup: string) {
indexof(input, lookup, 0, -1, countof(input,lookup))
};
your_table_name
| extend ToSubstring = substring("this.is.a.string.and.I.need.the.last.part", lastIndexof("this.is.a.string.and.I.need.the.last.part", ".")+1)
您可以使用负索引访问数组的最后一个成员 -1
。
例如这个:
print split("this.is.a.string.and.I.need.the.last.part", ".")[-1]
returns 单个 table,具有单个列和单个记录,值为 part