-2

I need to evaluate the output to see if it starts with a specific sequence.

For example if Cat1 = (A)

I want to verify that the entry begins with the value of Cat1 and can contain any text after it. If so then to output that entry.

I don't exactly know how to use wildcards in conjunction with the variable to allow entries such as

(A) First assignment
(A) Second assignment

to be selected and then to be transferred.

The portion that is in question is the following in my code:

 if(assign.title ==              ){
    SpreadsheetApp.openByUrl(url).getSheetByName(shet).appendRow([assign.title, marks.assignedGrade, 
    assign.maxPoints]);}
  }
Vega
  • 27,856
  • 27
  • 95
  • 103
  • Please read How to create a Minimal, Reproducible Example https://stackoverflow.com/help/mcve. Please add what you have tried so far to solve this yourself, e.g. research. – jasie Jan 16 '20 at 07:18

1 Answers1

0

Your issue can be solved by using Regular Expressions which essentially are special text strings used to describe a search pattern.

Therefore, if you want to search for the entries which begin with (A) and appendRow() like you mentioned above, you should use the following code snippet:

function theFunction() {

  var ss = SpreadsheetApp.openByUrl("YOUR_URL").getSheetByName("YOUR_SHEET_NAME");
  var regEx = /((A)).*/;
  //Getting the assign & marks variables

  if (assign.title.match(regEx))
    appendRow([assign.title, marks.assignedGrade, assign.maxPoints]);

}

The regular expression here is represented by the var regEx = /((A)).*/; which searches for a string to see if it starts with the (A) string.

Furthermore, I suggest you take a look at these links since they might be of help:

ale13
  • 5,679
  • 3
  • 10
  • 25
  • I reposted as a new question maybe something more specific. I need to match through multiple variables ... it is here if you wish to take a look at it. Thank you very much for your help though. https://stackoverflow.com/questions/59804934/use-of-regex-with-multiple-categories – user12658223 Jan 18 '20 at 21:19