Google Script to see if text contains a value

前端 未结 4 1193
既然无缘
既然无缘 2021-02-06 22:25

I have a google form that when the user submits it will trigger my function to run which is creating a summary of what they submitted as a Google Doc. I know it can automaticall

4条回答
  •  再見小時候
    2021-02-06 22:49

    I used the Google Apps Script method indexOf() and its results were wrong. So I wrote the small function Myindexof(), instead of indexOf:

    function Myindexof(s,text)
    {
      var lengths = s.length;
      var lengtht = text.length;
      for (var i = 0;i < lengths - lengtht + 1;i++)
      {
        if (s.substring(i,lengtht + i) == text)
          return i;
      }
      return -1;
    }
    
    var s = 'Hello!';
    var text = 'llo';
    if (Myindexof(s,text) > -1)
       Logger.log('yes');
    else
       Logger.log('no');
    

提交回复
热议问题