Java String Chomp chomp(String str)

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

Description

Removes last character if it is a newline.

License

Open Source License

Declaration

public static String chomp(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /** Removes last character if it is a newline. Like Perl's <code>chomp</code>. */
    public static String chomp(String str) {
        if (str.endsWith("\n")) {
            return str.substring(0, str.length() - 1);
        } else {/* w w  w  .ja va2s. co m*/
            return str;
        }
    }
}

Related

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