substring() method

The subtring() method is used in Apps Script to extract a specific portion of a string. It takes two parameters – the starting index and the ending index (optional) – and returns the substring between those indexes. If the ending index is not specified, the method extracts the substring from the starting index to the end of the string.

For example, if we have the string “Hello World”, and we want to extract the substring “World”, we can use the substring() method like this:

var str = "Hello World";
var subStr = str.substring(6);

This will assign the value “World” to the variable subStr.

Another example could be to extract the first three characters of a string:

var str = "California";
var subStr = str.substring(0, 3);

This will assign the value “Cal” to the variable subStr.

The substring() method can be useful in various scenarios, such as when we want to manipulate a portion of a larger string or extract a specific piece of data from a string.