Kusto查询语言将@字符拆分为最后一个项目

问题描述

如果我有一个字符串,例如: “这是一个字符串和我需要的最后一部分” 我正在尝试获取最后一个“。”之后的字符串的最后一部分,在本例中为“ 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的功能

有人提示吗?

解决方法

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

例如这个:

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

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

,

您可以尝试以下代码,并随时对其进行更改以满足您的需求:

let lastIndexof = (input:string,lookup: string) {
    indexof(input,lookup,-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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...