black flat screen computer monitor

Count Characters in a Google Sheet

I was trying explore some data in Google Sheet and stumble upon a unique problem. There were several columns and rows of data containing strings. I wanted to count specific string.

I wanted to find out how many “aD” in whole set.

What I needed to do is create custom function.

function countCharacter(input1, input2) {

  function cc(i1, i2) {
    var rgxp = new RegExp(i1, "g");
    return i2.match(rgxp).length;
  }

  if (input2 instanceof Array) {
    return cc(input1, input2.toString())
  } else {
    return cc(input1, input2)
  }

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: