Java Utililty Methods String Chomp

List of utility methods to do String Chomp

Description

The list of methods to do String Chomp are organized into topic(s).

Method

CharSequencechomp(CharSequence prefix, CharSequence full)
chomp
return full.subSequence(prefix.length(), full.length());
Stringchomp(final String s, final String suffix)
Remove the given suffix from the given string, if present.
if (hasLength(s) && hasLength(suffix) && s.endsWith(suffix)) {
    return s.substring(0, s.length() - suffix.length());
return s;
Stringchomp(String in)
chomp
if (in.endsWith("\r\n"))
    return in.substring(0, in.length() - 2);
else if (in.endsWith("\n"))
    return in.substring(0, in.length() - 1);
else
    return in;
Stringchomp(String inStr)
Deletes the Line Feed (10) and Carriage Return (13) fields of the given String.
if (inStr == null || "".equals(inStr)) {
    return inStr;
char lastChar = inStr.charAt(inStr.length() - 1);
if (lastChar == 13) {
    return inStr.substring(0, inStr.length() - 1);
} else if (lastChar == 10) {
    String tmp = inStr.substring(0, inStr.length() - 1);
...
Stringchomp(String options)
chomp
if (options == null || options.isEmpty()) {
    return options;
return options.substring(0, options.length() - 1);
Stringchomp(String path)
Remove the rightmost segment of the path and resource
String popped = "";
int index = path.lastIndexOf("/");
if (index != -1)
    popped = path.substring(0, index);
return popped;
Stringchomp(String s)
Removes the line-break from the end of the string.
if (s.endsWith("\r\n")) {
    return s.substring(0, s.length() - 2);
if (s.endsWith("\r") || s.endsWith("\n")) {
    return s.substring(0, s.length() - 1);
return s;
Stringchomp(String s)
Returns the supplied string with any trailing '\n' removed.
if (s.length() == 0)
    return s;
int l_1 = s.length() - 1;
if (s.charAt(l_1) == '\n') {
    return s.substring(0, l_1);
return s;
Stringchomp(String sd, String c)
chomp
if (sd == null) {
    return null;
if (sd.length() == 0) {
    return "";
if (sd.endsWith(c)) {
    return sd.substring(0, sd.length() - c.length());
...
Stringchomp(String str)
chomp
return (str.charAt(str.length() - 1) == '\n') ? str.substring(0, str.length() - 1) : str;