Fortinet white logo
Fortinet white logo

Script Reference Guide

String library

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.format
  • string.gmatch
  • string.gsub
  • string.len
  • string.lower
  • string.match
  • string.rep
  • string.reverse
  • string.sub
  • string.upper
  • string.starts_with
  • string.ends_with

Note:

  • If you want to use regular expression match, you can use string.match with Lua patterns.
  • All relational operators >, <, >=, <=, ~=, == apply to strings. Especially, == can be used to test if one string equals to another string.
  • string.find can 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” 

String library

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.format
  • string.gmatch
  • string.gsub
  • string.len
  • string.lower
  • string.match
  • string.rep
  • string.reverse
  • string.sub
  • string.upper
  • string.starts_with
  • string.ends_with

Note:

  • If you want to use regular expression match, you can use string.match with Lua patterns.
  • All relational operators >, <, >=, <=, ~=, == apply to strings. Especially, == can be used to test if one string equals to another string.
  • string.find can 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”