Count Characters in a Google Sheet

black flat screen computer monitor
Photo by Joan Gamell on Unsplash

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)