zeek/testing/btest/language/string-indexing.bro
Jon Siwek 55c515d50a Add array-style index accessor for strings. Addresses #422.
The index expression can take up to two indices for the start and end
index of the substring to return (e.g. "mystring[1,3]").  Negative
indices are allowed, with -1 representing the last character in the
string.  The indexing is not cyclic -- if the starting index is >= the
length of the string an empty string is returned, and if the ending
index is >= the length of the string then it's interpreted as the last
index of the string.  Assigning to substrings accessed like this isn't
allowed.
2012-12-20 17:13:06 -06:00

17 lines
292 B
Text

# @TEST-EXEC: bro -b %INPUT >out
# @TEST-EXEC: btest-diff out
local s = "0123456789";
print s[1];
print s[1,2];
print s[1,6];
print s[0,20];
print s[-2];
print s[-3,-1];
print s[-1,-10];
print s[-1,0];
print s[-1,5];
print s[20, 23];
print s[-20, 23];
print s[0,5][2];
print s[0,5][1,3][0];