The substring() function returns a string. The returned string is a piece of the string passed to the function. The syntax is as follows:

substring(<string>, <starting_position>, <characters_to_return>)

The <starting_position> value indicates the beginning of the new substring taken from the <string>. The first position of a string is position 0. The <characters_to_return> value indicates the number of characters to return starting with starting_position.

For the following script, the input is a 12-line text file. Each line has 10 characters.

For the first line of input, the substring() function returns the entire string. For subsequent lines of input, a character is removed from the beginning of the string.

When the starting position is greater than the number of characters in the original string, no characters are returned.

ASL Script (substring_do.asl):
y=0;
START {
 x:word eol
}
do {
 newstring=substring(x,y,10);
 print("New string ".newstring);
 y = y+1;
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (substring_do.txt):
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
Output:
$ sm_adapter --file=substring_do.txt substring_do.asl
New string 0123456789
New string 123456789
New string 23456789
New string 3456789
New string 456789
New string 56789
New string 6789
New string 789
New string 89
New string 9
New string 
New string 
$