DataScript: string.split

Note: This function is supported in Avi Vantage 18.2.5+.

Function string.split (source_string, delimiter)
source_string:split (delimiter)
Description Using a user-supplied delimiter, parses a string into substrings, and returns them in a Lua table of dimension equal to the number of substrings found.
Events All
Parameter source_string is the string to split.

delimiter is a single character by which to parse source_string.
Returns If either source_string or delimiter is nil, returns NIL.

Otherwise, returns a Lua table with elements corresponding to source_string, but split by each occurrence of delimiter. If there are no occurrences of delimiter in source_string, then the table returned will have only one element, the full string source_string.
Examples URI example
example_string = "www.example.com/this/is/an/example/uri"
split_results = string.split(example_string, "/")
avi.vs.log(split_results[6])
In the above example, split_results is a table containing:
split_results[1] → "www.example.com"
split_results[2] → "this"
split_results[3] → "is"
split_results[4] → "an"
split_results[5] → "example"
split_results[6] → "uri"
Consequently, the character string "uri" will be logged in the request logs.

Split miss example
example_string = "This string is just a sentence."
split_results = example_string:split(":")
avi.vs.log(split_results[1])
Notes
  1. In the above function reference, the prefix of the function name is dropped.
  2. Because example_string does not contain the colon delimiter, all its characters will be logged in the request logs, i.e., "This string is just a sentence."