String library
The FortiADC OS supports only the Lua string library. All other libraries are disabled. The string library includes the following string-manipulation functions:
string.byte(s, i)string.char(i1,i2…)string.dump(function)string.find(s, pattern)string.formatstring.gmatchstring.gsubstring.lenstring.lowerstring.matchstring.repstring.reversestring.substring.upperstring.starts_withstring.ends_with
Note:
- If you want to use regular expression match, you can use
string.matchwith Lua patterns. - All relational operators >, <, >=, <=, ~=, == apply to strings. Especially, == can be used to test if one string equals to another string.
string.findcan be used to test whether one string contains another string.
For a tutorial on scripting with the Lua string library, see http://lua-users.org/wiki/StringLibraryTutorial.
For example: uri:starts_with (b), uri:ends_with (b)
Example 1:
a=12
b=string.format(“%s, pi=%.4f”, a, 3.14)
• {s:byte(1,-1)}
Example 2:
str = “abc\1\2\0”
t={str:byte(1,-1)}
t is a table like an array to store the string.
t[1] is 97, t[2] is 98, t[3] is 99, t[4] is 1, t[5] is 2, t[6] is 0.
• {s:sub(1, 3)}
str="abcdefg"
Example 3:
str = “abc\1\2\0”
t={str:byte(1,-1)}
t is a table like an array to store the string.
t[1] is 97, t[2] is 98, t[3] is 99, t[4] is 1, t[5] is 2, t[6] is 0.
• {s:sub(1, 3)}
str="abcdefg"
test=str:sub(2,5)
debug("return: %s \n", test)
log("record a log")
result: “bcde”