remove Left Pad - Java java.lang

Java examples for java.lang:String Pad

Description

remove Left Pad

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        String pad = "com";
        System.out.println(removeLeftPad(str, pad));
    }/*w  w w.  j a v  a  2  s.  co  m*/

    public static String removeLeftPad(String str, String pad) {
        while (str.startsWith(pad)) {
            str = str.replaceFirst(pad, "");
        }
        return str;
    }
}

Related Tutorials