Java String Trim Left leftTrim(String str)

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

Description

Removes leading whitespaces.

License

Open Source License

Parameter

Parameter Description
str String to treat

Return

str without leading whitespaces

Declaration

public static String leftTrim(String str) 

Method Source Code

//package com.java2s;
/*/*from  w ww . jav a2 s .com*/
 *  File: MiscUtil.java 
 *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
 *  A commercial license is available, see http://www.jaret.de.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 */

public class Main {
    /**
     * Removes leading whitespaces.
     * 
     * @param str String to treat
     * @return str without leading whitespaces
     */
    public static String leftTrim(String str) {
        if (str.length() == 0) {
            return str;
        }
        int i = 0;
        while (i < str.length()) {
            char c = str.charAt(i);
            if (Character.isWhitespace(c)) {
                i++;
            } else {
                break;
            }
        }
        return str.substring(i);
    }
}

Related

  1. leftTrim(final String input, final char charToTrim)
  2. leftTrim(String input, char charToTrim)
  3. leftTrim(String rawString)
  4. lefttrim(String str)
  5. leftTrim(String str)
  6. leftTrim(String string)
  7. leftTrim(String value)
  8. leftTrim(StringBuilder pStringBuilder)
  9. leftTrimSlashes(String s)