Here you can find the source of countLines(String text)
Parameter | Description |
---|---|
text | The test |
static public int countLines(String text)
//package com.java2s; /**/*from w ww .j a v a 2 s .com*/ * * $Id: Utils.java 28 2005-06-20 13:13:35Z rej $ * * Copyright (c) 2002 Sun Microsystems, Inc. * * * * See the file "license.terms" for information on usage and redistribution * * of this file, and for a DISCLAIMER OF ALL WARRANTIES. **/ public class Main { /** * Count the number of lines in a string * @param text The test * @return the count */ static public int countLines(String text) { if (text == null) return 0; int count = 1; char arr[] = text.toCharArray(); for (char anArr : arr) { if (anArr == '\n') ++count; } return count; } }