code: protected static int countPreceding(String line, int index, char ch) {
  
          int i;
          for (i = index - 1; i >= 0; i--) {
              if (line.charAt(i) != ch) {
                  break;
              }
          }
          return index - 1 - i;
      }
docs: Counts the number of successive times 'ch' appears in the
  'line' before the position indicated by the 'index'.<p>
  
  @param line the line to count
  @param index the index position to start
  @param ch the character to count
  
  @return the number of successive times 'ch' appears in the 'line'
  before the position indicated by the 'index'