Java String Trim Right rightTrim(StringBuilder pStringBuilder)

Here you can find the source of rightTrim(StringBuilder pStringBuilder)

Description

Similar to the Perl chomp command.

License

Open Source License

Parameter

Parameter Description
pStringBuilder The StringBuffer object to remove leading and trailing whitespace characters from.

Return

StringBuilder the chomped string.

Declaration

public static StringBuilder rightTrim(StringBuilder pStringBuilder) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w  ww .j  a  v  a 2  s  .  c  om
     * Similar to the Perl chomp command. Removes all trailing
     * whitespace.
     *
     * @param pStringBuilder The StringBuffer object to remove leading and trailing whitespace
     * characters from.
     * @return StringBuilder the chomped string.
     */
    public static StringBuilder rightTrim(StringBuilder pStringBuilder) {
        int endPos = pStringBuilder.length() - 1;
        while (endPos != -1 && Character.isWhitespace(pStringBuilder.charAt(endPos))) {
            pStringBuilder.deleteCharAt(endPos);
        }

        return pStringBuilder;
    }

    /**
     * Similar to the Perl chomp command. Removes all trailing
     * whitespace.
     *
     * @param pString The String object to remove leading and trailing whitespace
     * characters from.
     * @return String the chomped string.
     */
    public static String rightTrim(String pString) {
        return rightTrim(new StringBuilder(pString)).toString();
    }
}

Related

  1. rightTrim(String str)
  2. rightTrim(String str)
  3. rightTrim(String string)
  4. rightTrim(String value)
  5. rightTrim(String[] values)
  6. rightTrimNewLineChars(String input)
  7. rightTrimSize(String s)
  8. rightTrimSlashes(String s)
  9. rightTrimString(String originalString)