split() / array_length()
split(text, separator) cuts a string wherever the separator appears and returns the pieces as a list
(a dynamic array):
print Parts = split("ws-prg-011.kestrelbay.example", ".")
// ["ws-prg-011","kestrelbay","example"]
Reading the parts
split(x, ".")[0]is the first piece,[1]the second, and[-1]the last.- An index past the end gives an empty value, not an error.
- The pieces are dynamic values. Wrap them in
tostring()before you compare, group or sort by them.
array_length()
array_length(list) returns the number of items in a list: from split(), from
make_set(), or from a list in a dynamic column. It returns null when
the value isn’t a list.
Things to know
- The separator is plain text, not a regular expression. For pattern-based cutting, use
extract(). - If the separator does not occur, you get a list with one item, the whole string.
- Two separators in a row give an empty piece between them:
split("a,,b", ",")has three items. split()also takes an optional third argument: the index of the one piece to return (still as a one-item list).
Examples
SigninLogs
| where Location == "GB"
| extend Name = tostring(split(UserPrincipalName, "@")[0])
| distinct Name[0] is the first part. tostring() turns the dynamic value into a normal string.
DeviceProcessEvents
| where FileName in ("OneDrive.exe", "MpCmdRun.exe", "explorer.exe")
| extend Folders = split(FolderPath, @"\")
| summarize Depth = max(array_length(Folders)) by FileNameDeviceNetworkEvents
| where isnotempty(RemoteUrl)
| extend Host = tostring(split(RemoteUrl, ".")[0])
| summarize Urls = dcount(RemoteUrl) by Host
| sort by Urls descPractice it
+ 1 in the full SC-200 set · all exercises