Java String Trim Right rightTrim(final String aString)

Here you can find the source of rightTrim(final String aString)

Description

Copies this String removing white space characters from the end of the string.

License

Open Source License

Parameter

Parameter Description
aString the String to trim.

Return

a new String with characters \\u0020 removed from the end

Declaration

public static String rightTrim(final String aString) 

Method Source Code

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

public class Main {
    /**/*from  w  w  w .  j ava2 s  .c  om*/
     * Copies this String removing white space characters from the end of the string.
     *
     * @param aString the String to trim.
     * @return a new String with characters <code>\\u0020</code> removed from the end
     */
    public static String rightTrim(final String aString) {
        if (aString == null) {
            return null;
        }
        int end = aString.length() - 1;
        while ((end >= 0) && (aString.charAt(end) <= ' ')) {
            end--;
        }
        if (end == aString.length() - 1) {
            return aString;
        }
        return aString.substring(0, end + 1);
    }
}

Related

  1. rightTrim(final String input, final char charToTrim)
  2. rightTrim(String input, char charToTrim)
  3. rightTrim(String s)
  4. rightTrim(String s, char c)