The substr() method is used to extract a portion of a string based on a specified starting index and length. The method takes two arguments: the starting index and the length of the substring to be extracted.
For example, string.substr(2, 4) would extract a substring of four characters starting from the third character (index 2) of the string.
Here are two examples of how to use the substr() method in Apps Script:
1. Extracting the first name from a full name string
In this example, the substr() method is used to extract the portion of the fullName string before the first space character, which represents the first name.
2. Extracting a portion of a string based on a dynamic length
In this example, the substr() method is used to extract a portion of the str string based on a dynamic starting and ending index, resulting in a substring of a specific length.