Java String Line Count countLine(String contents, int index)

Here you can find the source of countLine(String contents, int index)

Description

count Line

License

Open Source License

Declaration

public static int countLine(String contents, int index) 

Method Source Code

//package com.java2s;
/**/*from   w  w  w. java2s.  c om*/
 * Copyright (c) 2015 SK holdings Co., Ltd. All rights reserved.
 * This software is the confidential and proprietary information of SK holdings.
 * You shall not disclose such confidential information and shall use it only in
 * accordance with the terms of the license agreement you entered into with SK holdings.
 * (http://www.eclipse.org/legal/epl-v10.html)
 */

public class Main {

    public static int countLine(String contents, int index) {
        int count = 0;
        if (index < 0 || index > contents.length()) {
            return 0;
        }

        for (int i = 0; i < index; i++) {
            if ('\n' == contents.charAt(i))
                count++;
        }
        return count;
    }
}

Related

  1. countLine(CharSequence str)
  2. countLine(String content)
  3. countLineBreaks(final String replacementString)
  4. countLineBreaks(String text)
  5. countLineEnds(CharSequence string, int startPos)
  6. countLines(final String content, final String lineBreak)