首页 > 解决方案 > Kusto 查询语言拆分@字符并取最后一项

问题描述

如果我有一个字符串,例如:“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 的功能。

有人有提示吗?

标签: azureazure-data-explorer

解决方案


您可以使用负索引访问数组的最后一个成员-1

例如这个:

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

返回单个表,具有单列和单条记录,其值为part


推荐阅读