Backward match

Here is an easy tip about the backward match.

Backward match

 

Source code

function backwardMatch() {
  var res = false;
  var str1 = "Startup";
  var str2 = "Berlin Startup";
  var len1 = str1.length;
  var len2 = str2.length;
  var remain = str2.length - str2.indexOf(str1);
  if (len1 === remain){
    res = true;
  }
  Browser.msgBox("The end of str2 matches str1? -> " + res);
}

 

Steps to check the backward match

Google Apps Script doesn’t supply the backward match function. Thus you have to code to do achieve it.

The followings are steps to check the backward match;

(1) Get the length of str1.

(2) Get the start position which is match with str1.

(3) Substract (2)’s result from the length of str2.

(4) Compare (1)’s result with (3)’s result.

Leave a Comment