Here you can find the source of countLineBreaks(final String replacementString)
public static int countLineBreaks(final String replacementString)
//package com.java2s; public class Main { /**//from ww w . j a v a 2 s .co m * @return the number of line breaks in the passed string. */ public static int countLineBreaks(final String replacementString) { int lineBreaks = 0; int ignoreNextNAt = -1; //we may have line breaks with \r\n, or only \n or \r final int len = replacementString.length(); for (int i = 0; i < len; i++) { char c = replacementString.charAt(i); if (c == '\r') { lineBreaks++; ignoreNextNAt = i + 1; } else if (c == '\n') { if (ignoreNextNAt != i) { lineBreaks++; } } } return lineBreaks; } }