Extracting Substrings

A substring is a string within a string. For example, tab and able are both substrings of table. You can use the[ ] operator to specify a substring using this syntax:

string[ [ start, ] length ]

string is the string containing the substring.

start is a number specifying where the substring starts. The first character of string counts as 1. If start is 0 or a negative number, the starting position is assumed to be 1. If start is omitted, the starting position is calculated according to the following formula:

string.length - substring.length + 1