code: public static int getLineNumber(String text, int posChar) {
  
  	int len = Math.min(posChar, text.length());
  	int result = 1;
  
  	for (int i = 0; i < len; i++) {
  
  	    if (text.charAt(i) == '\n') result++;
  	}
  
  	return result;
      }
docs: returns the line number of the given char in the text