Java String Line Count countLines(String s)

Here you can find the source of countLines(String s)

Description

Count the number of lines of text in given string.

License

Open Source License

Parameter

Parameter Description
s the string

Return

number of lines

Declaration

public static int countLines(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww w.j a v  a  2  s  .c o m
     * Count the number of lines of text in given string.
     * 
     * @param s the string
     * @return number of lines
     */
    public static int countLines(String s) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '\n') {
                count++;
            }
        }
        return count;
    }
}

Related

  1. countLines(String aMessage)
  2. countLines(String buffer)
  3. countLines(String data)
  4. countLines(String input)
  5. countLines(String o)
  6. countLines(String s)
  7. countLines(String str)
  8. countLines(String text)
  9. countLines(String text)