Java String Trim Left leftTrim(String input, char charToTrim)

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

Description

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

License

Common Public License

Declaration

public static String leftTrim(String input, char charToTrim) 

Method Source Code

//package com.java2s;
/*/*ww w . ja va2  s  . co  m*/
 * @author Fabio Zadrozny
 * Created: June 2005
 * License: Common Public License v1.0
 */

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

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

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

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

Related

  1. leftAndRightTrim(String input, char charToTrim)
  2. leftTrim(char[] text, int offset)
  3. leftTrim(final String aString)
  4. leftTrim(final String input)
  5. leftTrim(final String input, final char charToTrim)
  6. leftTrim(String rawString)
  7. leftTrim(String str)
  8. lefttrim(String str)
  9. leftTrim(String str)