Trims any leading instances of the passed String from the subject String. - Java java.lang

Java examples for java.lang:String Trim

Description

Trims any leading instances of the passed String from the subject String.

Demo Code


//package com.java2s;

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

    /**
     * Trims any leading instances of the passed String from the subject
     * String.
     */
    public static String trimLeading(final String string,
            final String remove) {
        String process = string;

        while (process.startsWith(remove))
            process = process.substring(remove.length());

        return process;
    }
}

Related Tutorials