Java String Chomp chompLast(String str)

Here you can find the source of chompLast(String str)

Description

chomp Last

License

Apache License

Declaration

public static String chompLast(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from ww w .j  a  v  a2  s. com
       * @deprecated
       */
    public static String chompLast(String str) {
        return chompLast(str, "\n");
    }

    /**
       * @deprecated
       */
    public static String chompLast(String str, String sep) {
        if (str.length() == 0) {
            return str;
        }
        String sub = str.substring(str.length() - sep.length());
        if (sep.equals(sub)) {
            return str.substring(0, str.length() - sep.length());
        }
        return str;
    }

    public static String substring(String str, int start) {
        if (str == null) {
            return null;
        }
        if (start < 0) {
            start = str.length() + start;
        }
        if (start < 0) {
            start = 0;
        }
        if (start > str.length()) {
            return "";
        }
        return str.substring(start);
    }

    public static String substring(String str, int start, int end) {
        if (str == null) {
            return null;
        }
        if (end < 0) {
            end = str.length() + end;
        }
        if (start < 0) {
            start = str.length() + start;
        }
        if (end > str.length()) {
            end = str.length();
        }
        if (start > end) {
            return "";
        }
        if (start < 0) {
            start = 0;
        }
        if (end < 0) {
            end = 0;
        }
        return str.substring(start, end);
    }

    public static boolean equals(String str1, String str2) {
        return str1 == null ? false : str2 == null ? true : str1.equals(str2);
    }
}

Related

  1. chomp(String value)
  2. chomp(StringBuilder sb)
  3. chompAllAndTrim(String str)
  4. chompClosureOpen(String expr)
  5. chompHeader(String str, String prex)
  6. chompLast(String str, String sep)
  7. chompNewLine(String line)