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