Java String Line Count countLines(String o)

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

Description

This method counts how many lines an input string would take if it were outputed onto the screen or into a file.

License

Open Source License

Parameter

Parameter Description
o String to count line for

Return

an int with the number of output lines the string would take

Declaration

public static int countLines(String o) 

Method Source Code

//package com.java2s;
/**/*from w w  w.j a  v a 2s.c  o  m*/
 * <PRE>
 * Name   : com.solidmatrix.regxmaker.util.shared.ConsoleUtils
 * Project: RegXmaker Library
 * Version: 1.1
 * Tier   : N/A (Function Class)
 * Author : Gennadiy Shafranovich
 * Purpose: General utilities for console based applications
 *
 * Copyright (C) 2001, 2004 SolidMatrix Technologies, Inc.
 * This file is part of RegXmaker Library.
 *
 * RegXmaker Library is is free software; you can redistribute it and/or modify
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * RegXmaker library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Comments: Full, with javadoc.
 *
 * Modification History
 *
 * 01-28-2001  GS Created
 * 07-02-2001  GS Added a more general readFull() method to read 
 *                entire contents of a stream. readFullFile now
 *                used this method to read from an underlying
 *                FileInputStream.
 *
 * 07-05-2004 YS Added licensing information
 * </PRE>
 */

public class Main {
    private static String line = System.getProperty("line.separator");

    /**
     * This method counts how many lines an input string would take if
      * it were outputed onto the screen or into a file. Count depends on 
      * the number of line separators in the string.
     *
     * @param   o  String to count line for
     * @return     an int with the number of output lines the string would take
     */
    public static int countLines(String o) {
        int lines = 0;
        int start = o.indexOf(line);
        while (start >= 0) {
            lines++;
            start = o.indexOf(line, start);
        } //while

        return lines;
    }
}

Related

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