trim a string from left - Java java.lang

Java examples for java.lang:String Trim

Description

trim a string from left

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String text = "java2s.com";
        System.out.println(ltrim(text));
    }/*from   w  ww  .j a v  a2  s  .  c o m*/

    public static final String ltrim(final String text) {
        return ltrim(text, null);
    }

    public static final String ltrim(final String text, String trimText) {
        if (text == null) {
            return null;
        }
        if (trimText == null) {
            trimText = " ";
        }
        int pos = 0;
        for (; pos < text.length(); pos++) {
            if (trimText.indexOf(text.charAt(pos)) < 0) {
                break;
            }
        }
        return text.substring(pos);
    }
}

Related Tutorials