Java String Sub String substringAndchopLastNewline(String text, int start_pos, int end_pos)

Here you can find the source of substringAndchopLastNewline(String text, int start_pos, int end_pos)

Description

Gets text substring from 'start_pos' position till 'end_pos' position and chop last symbol if it is newline \n symbol.

License

Open Source License

Declaration

public static String substringAndchopLastNewline(String text, int start_pos, int end_pos) 

Method Source Code

//package com.java2s;
/* StringUtilRegular.java - realm of regular expressions.
 *
 * Copyright (c) 2005-2011 Andrew Krizhanovsky <andrew.krizhanovsky at gmail.com>
 * Distributed under GNU Public License.
 *///w  w  w .jav  a2  s  .c  o  m

public class Main {
    private final static String NULL_STRING = new String();

    /** Gets text substring from 'start_pos' position till 'end_pos' position
     * and chop last symbol if it is newline \n symbol.
     */
    public static String substringAndchopLastNewline(String text, int start_pos, int end_pos) {

        if (start_pos < 0 || start_pos >= end_pos || end_pos > text.length() - 1) {
            return NULL_STRING;
        }

        if (end_pos > 0 && '\n' == text.charAt(end_pos - 1)) {
            end_pos--;
        }

        return text.substring(start_pos, end_pos);
    }
}

Related

  1. substringAfterLast(String str, String separator)
  2. substringAfterLast(String string, String delimiter)
  3. substringAfterLast(String text, char after)
  4. subStringAfterLastSymbol(String inStr, char symbol)
  5. substringAfterReturnAll(String str, String before)
  6. subStringArray(String in[], int start, int end)
  7. substringBaseName(String baseName, int extraCharsNumber)
  8. substringBefore(final String str, final String separator)
  9. substringBefore(final String string, final String separator)