Java String Chomp chomp(String str)

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

Description

chomp

License

Open Source License

Declaration

public static String chomp(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static String chomp(String str) {
        return chomp(str, "\n");
    }/*from  w  w w  .j av a2  s .c om*/

    /**
     * <p>
     * Remove the last value of a supplied String, and everything after it from
     * a String.
     * </p>
     * 
     * @param str
     *            String to chomp from
     * @param sep
     *            String to chomp
     * @return String without chomped ending
     * @throws NullPointerException
     *             if str or sep is <code>null</code>
     */
    public static String chomp(String str, String sep) {
        int idx = str.lastIndexOf(sep);
        if (idx != -1) {
            return str.substring(0, idx);
        } else {
            return str;
        }
    }
}

Related

  1. chomp(String s)
  2. chomp(String s)
  3. chomp(String sd, String c)
  4. chomp(String str)
  5. chomp(String str)
  6. chomp(String str)
  7. chomp(String str)
  8. chomp(String str, String sep)
  9. chomp(String str, String separator)