Java String Trim Left ltrim(String str, String charList)

Here you can find the source of ltrim(String str, String charList)

Description

ltrim

License

Open Source License

Declaration

public static String ltrim(String str, String charList) 

Method Source Code

//package com.java2s;
/*/*  w  w  w.java2  s .co m*/
 * -----LICENSE START-----
 * JSHManager - A Java-based tool for managing one's ScoreHero account.
 * Copyright (C) 2008 Tim Mullin
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * -----LICENSE END-----
*/

public class Main {
    public static String ltrim(String str) {
        return ltrim(str, null);
    }

    public static String ltrim(String str, String charList) {
        int start = 0, len = str.length();

        if (null == charList)
            for (int i = 0; i < len; i++)
                if (Character.isWhitespace(str.charAt(i)))
                    start++;
                else
                    break;
        else
            for (int i = 0; i < len; i++)
                if (charList.indexOf(str.charAt(i)) >= 0)
                    start++;
                else
                    break;

        return str.substring(start);
    }
}

Related

  1. ltrim(String src, char ch, int nLen)
  2. ltrim(String str)
  3. ltrim(String str)
  4. ltrim(String str)
  5. ltrim(String str)
  6. ltrim(String str, String defaultValue)
  7. ltrim(String text, char c)
  8. ltrimCount(final String input)
  9. ltrimNewline(String s)