Java String Trim Left ltrim(String s)

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

Description

Trims the space characters from the beginning of a string.

License

Open Source License

Parameter

Parameter Description
s the string to edit

Return

the trimmed string

Declaration

public static final String ltrim(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   www  .j av  a 2 s  .co  m
     * Trims the space characters from the beginning of a string.
     * For example, the call <CODE>ltrim ("eeTennessee", 'e')</CODE>
     * returns the string "Tennessee".<BR>
     * @param s the string to edit
     * @return the trimmed string
     */
    public static final String ltrim(String s) {
        int count = s.length();
        int st = 0;
        while ((st < count) && isSpace(s.charAt(st))) {
            st++;
        }
        return st > 0 ? s.substring(st, count) : s;
    }

    public static final boolean isSpace(String s) {
        if (s != null) {
            int len = s.length();
            for (int i = 0; i < len; i++) {
                char c = s.charAt(i);
                if (c != ' ' && c != '\t' && c != '\n' && c != '\r') {
                    return false;
                }
            }
        }
        return true;
    }

    private static boolean isSpace(char c) {
        return c <= ' ';
    }
}

Related

  1. ltrim(String pString)
  2. ltrim(String s)
  3. ltrim(String s)
  4. ltrim(String s)
  5. ltrim(String s)
  6. lTrim(String s)
  7. ltrim(String s)
  8. ltrim(String s)
  9. ltrim(String s)