Java String Line Count countLine(String content)

Here you can find the source of countLine(String content)

Description

count Line

License

Apache License

Declaration

public static int countLine(String content) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int countLine(String content) {
        return countHappens('\n', content) + 1;
    }//from   www  .  j a v a2 s .  co  m

    /**
     *
     * @param chr
     * @param string
     * @return count
     */
    public static int countHappens(char chr, CharSequence string) {
        if (string == null) {
            return 0;
        }
        int length = string.length();
        int count = 0;
        for (int i = 0; i < length; i++) {
            if (string.charAt(i) == chr)
                count++;
        }
        return count;
    }
}

Related

  1. countLine(CharSequence str)
  2. countLine(String contents, int index)
  3. countLineBreaks(final String replacementString)
  4. countLineBreaks(String text)
  5. countLineEnds(CharSequence string, int startPos)