Look through the string and count the spaces
549057
def get_indent(self, string):
        
        indent_amt = 0

        if string[0] == '\t':
            return '\t'
        for char in string:
            if char == ' ':
                indent_amt += 1
            else:
                return ' ' * indent_amt
401998
function countCharFromStr(str, ch) {
    let strArr = [...str];
    let count = 0;
    for (let k in strArr) {
        if (strArr[k] === ch) {
            count++
        }
    }
    return count
}
1114780
function countSpaces(tokens) {
            const before = tokens.arrow.range[0] - tokens.before.range[1];
            const after = tokens.after.range[0] - tokens.arrow.range[1];

            return { before, after };
        }
1056692
def count_indents_length_last_line(self, spacecount, tabs=0, back=5):
        
        if not self.has_space():
            return 0
        lines = self.get_surrounding_lines(back, 0)

        for line in reversed(lines):
            if not line.string.isspace():
                return line.count_indents_length(spacecount, tabs)
        return (0, 0)
682785
def get_leading_spaces(data):
    
    spaces = ''
    m = re.match(r'^(\s*)', data)
    if m:
        spaces = m.group(1)
    return spaces
1086361
def count_indents(self, spacecount, tabs=0, offset=0):
        
        if not self.has_space(offset=offset):
            return 0
        spaces = 0
        indents = 0
        for char in self.string[self.pos + offset - self.col:]:
            if char == ' ':
                spaces += 1
            elif tabs and char == '\t':
                indents += 1
                spaces = 0
            else:
                break
            if spaces == spacecount:
                indents += 1
                spaces = 0
        return indents
1298908
def get_backspace_count(self, buffer):
        
        if TriggerMode.ABBREVIATION in self.modes and self.backspace:
            if self._should_trigger_abbreviation(buffer):
                abbr = self._get_trigger_abbreviation(buffer)
                stringBefore, typedAbbr, stringAfter = self._partition_input(buffer, abbr)
                return len(abbr) + len(stringAfter)

        if self.parent is not None:
            return self.parent.get_backspace_count(buffer)

        return 0
741395
def check_surrounding_whitespaces(self, definition, docstring):
        """"""
        if docstring:
            lines = ast.literal_eval(docstring).split('\n')
            if lines[0].startswith(' ') or \
                    len(lines) == 1 and lines[0].endswith(' '):
                return violations.D210()
287442
private int countOccurrences(String haystack, char needle) {
        int count = 0;
        for (int i = 0; i < haystack.length(); i++) {
            if (haystack.charAt(i) == needle)
                count++;
        }
        return count;
    }
1189568
private int countNLs() {
        String s = getText();
        int c = 0;
        for(int i=0; i< s.length(); i++)
            if ( s.charAt(i) == '\n' )
                c++;
        return c;
    }
439530
private static int countAnchors(String formatString) {
        Matcher m = FORMATTER_ANCHOR.matcher(formatString);
        int count = 0;
        int start = 0;
        while (m.find(start)) {
            ++count;
            start = m.end();
        }

        return count;
    }
1231245
private static int findMinimumLeadingSpaces(String line, int count) {
        int length = line.length();
        int index = 0;
        while (index < length && index < count && Character.isWhitespace(line.charAt(index))) index++;
        return index;
    }
1008019
@Nonnegative
  public static int getLeadingWhitespaceCount (@Nullable final String s)
  {
    int ret = 0;
    if (s != null)
    {
      final int nMax = s.length ();
      while (ret < nMax && Character.isWhitespace (s.charAt (ret)))
        ++ret;
    }
    return ret;
  }
1288892
function getCharCount(e, s) {
  s = s || ",";
  return getInnerText(e).split(s).length;
}
920572
function consumeWhitespace(remaining) {
  var match = remaining.match(/^\s+/);

  if (match) {
    var consumed = match[0];
    remaining = remaining.substring(consumed.length);
  }

  return remaining;
}
771407
def str(self, space=False):
    """"""
    return "%s/%s (%s)" % (str(int(self.id)).rjust(space and 4),
                           self.name.ljust(space and 50),
                           "; ".join(str(a) for a in self.args))
591762
private int countNonNewline(String str, int off, int len) {
    for(int cnt = 0; cnt < len; cnt++) {
      final int pos = off + cnt;
      if(str.charAt(pos) == UNIX_NEWLINE) {
        return cnt;
      }
      if(str.charAt(pos) == CARRIAGE_RETURN) {
        return cnt;
      }
    }
    return len;
  }