Here you can find the source of chomp(String str, String sep)
Remove the last value of a supplied String, and everything after it from a String.
Parameter | Description |
---|---|
str | String to chomp from |
sep | String to chomp |
Parameter | Description |
---|---|
NullPointerException | if str or sep is <code>null</code> |
public static String chomp(String str, String sep)
//package com.java2s; public class Main { public static String chomp(String str) { return chomp(str, "\n"); }// w w w . j a va 2 s .c o m /** * <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; } } }