Here you can find the source of countLines(String s)
Parameter | Description |
---|---|
s | the string |
public static int countLines(String s)
//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; } }