Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find text in a string using google script?

I tried indexOf(), findText() and other few methods for finding a string pattern in a text in google app script. None of the above method works.

var str="task is completed";

I'm getting this string from google spreadsheet.

I just want to find whether the above string contains a string "task" .

like image 649
Arun Prakash Avatar asked May 19 '15 11:05

Arun Prakash


1 Answers

You need to check if the str is present:

if (str) {
    if (str.indexOf('task') > -1) {
        // Present
    }
}

Alternatively, you can use test and regex:

/task/.test("task is completed");

/task/.test(str);
  1. /task/: Regex to match the 'task'
  2. test: Test the string against regex and return boolean
like image 169
Tushar Avatar answered Sep 18 '22 14:09

Tushar