Forum Discussion
Patrick Naughton
Jun 01, 2019Brass Contributor
Scalar function request: lastindexof
documentation copied from indexof
lastindexof()
Function reports the zero-based index of the last occurrence of a specified string within input string.
If lookup or input string is not of string type - forcibly casts the value to string.
Syntax
lastindexof(source,lookup[,start_index[,length]])
Arguments
- source: input string.
- lookup: string to seek.
- start_index: search start position (optional).
- length: number of character positions to examine (optional).
Returns
Zero-based index position of lookup.
Returns -1 if the string is not found in the input.
In case of irrelevant (less than 0) start_index or length parameter - returns null.
Examples
print idx1 = lastindexof("/abc/cde/fgh", "/") // lookup found in input string , idx2 = lastindexof("/abc/cde/fgh", "/", 1, 6) // lookup found in researched range , idx3 = lastindexof("/abc/cde/fgh", "/", 1, 2) // search starts from index 1, but stops after 2 chars, so full lookup can't be found , idx4 = lastindexof("/abc/cde/fgh", "/", 0, 3) // search starts after occurrence of lookup , idx5 = lastindexof("/abc/cde/fgh", "/", -1) // invalid input , idx6 = lastindexof(1231231, 2) // two first parameters were forcibly cast to strings "1231231" and "2"
idx1 idx2 idx3 idx4 idx5 idx6
8 | 4 | -1 | 0 | 4 |
- Meir_Mendelovich
Microsoft
Hi, query language asks should go here: https://techcommunity.microsoft.com/t5/Azure-Data-Explorer/bd-p/Kusto