Java String Trim Left ltrim(String source)

Here you can find the source of ltrim(String source)

Description

Left trim: remove spaces to the left of a String.

License

Apache License

Parameter

Parameter Description
str The String to left trim

Return

The left trimmed String

Declaration

public static String ltrim(String source) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   ww  w .ja  va  2 s.  co  m*/
     * Left trim: remove spaces to the left of a String.
     * 
     * @param str
     *            The String to left trim
     * @return The left trimmed String
     */
    public static String ltrim(String source) {
        if (source == null)
            return null;
        int from = 0;
        while (from < source.length() && isSpace(source.charAt(from)))
            from++;

        return source.substring(from);
    }

    /**
     * Determines whether or not a character is considered a space. A character
     * is considered a space in Kettle if it is a space, a tab, a newline or a
     * cariage return.
     * 
     * @param c
     *            The character to verify if it is a space.
     * @return true if the character is a space. false otherwise.
     */
    public static final boolean isSpace(char c) {
        return c == ' ' || c == '\t' || c == '\r' || c == '\n';
    }
}

Related

  1. ltrim(String s)
  2. ltrim(String s, char character)
  3. ltrim(String s, Character c)
  4. ltrim(String source)
  5. ltrim(String source)
  6. ltrim(String src, char ch, int nLen)
  7. ltrim(String str)
  8. ltrim(String str)
  9. ltrim(String str)