Java String Trim Right rightTrim(String input, char charToTrim)

Here you can find the source of rightTrim(String input, char charToTrim)

Description

Removes the occurrences of the passed char in the beggining of the string.

License

Common Public License

Declaration

public static String rightTrim(String input, char charToTrim) 

Method Source Code

//package com.java2s;
/*//from   w  ww.jav  a  2  s .c o m
 * @author Fabio Zadrozny
 * Created: June 2005
 * License: Common Public License v1.0
 */

public class Main {
    /**
     * Removes whitespaces at the beggining of the string.
     */
    public static String rightTrim(String input) {
        int len = input.length();
        int st = 0;
        int off = 0;
        char[] val = input.toCharArray();

        while ((st < len) && (val[off + len - 1] <= ' ')) {
            len--;
        }
        return input.substring(0, len);
    }

    /**
     * Removes the occurrences of the passed char in the beggining of the
     * string.
     */
    public static String rightTrim(String input, char charToTrim) {
        int len = input.length();
        int st = 0;
        int off = 0;
        char[] val = input.toCharArray();

        while ((st < len) && (val[off + len - 1] == charToTrim)) {
            len--;
        }
        return input.substring(0, len);
    }
}

Related

  1. rightTrim(final String aString)
  2. rightTrim(final String input, final char charToTrim)
  3. rightTrim(String s)
  4. rightTrim(String s, char c)
  5. rightTrim(String src)
  6. rightTrim(String str)