get a specified line in variable and Find all indexes of a specified word from a variable in Google script -
here example: hello
how you, how friend.
i fine
take care
so here want second line output("how you, how friend.") , index number of "how". want index numbers how = 0 , 3 (since there 2 occurrences.
here example:
function testit99() { var texttest = "how you, how friend."; //remove commas texttest = texttest.replace(",", ""); logger.log('texttest: ' + texttest); texttest = texttest.replace(".", ""); logger.log('texttest: ' + texttest); //put words array var arrayofwords = texttest.split(" "); logger.log('texttest: ' + texttest); var arrayofindexes = []; var i=0; (i=0;i<arrayofwords.length;i+=1) { if (arrayofwords[i]==="how") { arrayofindexes.push(i) }; }; logger.log("indexes of 'how' are: " + arrayofindexes) };
Comments
Post a Comment