The split()
method is a string method in Apps Scripts that is used to split a string into an array of substrings based on a specified separator. The resulting array can then be used for further manipulation or processing.
For example, if we have a string “London,Paris,Tokyo” and we want to split it into an array of city names, we can use the split()
method as follows:
var cities = "London,Paris,Tokyo";
var cityArray = cities.split(",");
The resulting cityArray
would be an array with three elements: “London”, “Paris”, and “Tokyo”.
Another example is when we want to split a string into words. We can use the split()
method with a space (” “) as the separator as follows:
var sentence = "The quick brown fox";
var wordsArray = sentence.split(" ");
The resulting wordsArray
would be an array with four elements: “The”, “quick”, “brown”, and “fox”.
The split()
method is a powerful tool for manipulating strings in Apps Scripts and can be used in a variety of applications, such as parsing data from spreadsheets or working with text-based APIs.