strip from Start of a string - Java java.lang

Java examples for java.lang:String Strip

Introduction

The following code shows how to strip Start

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String str = "java2s.com";
        String stripChars = "java2s.com";
        System.out.println(stripStart(str, stripChars));
    }/* ww  w .  j  ava2  s  . c o m*/

    public static final int INDEX_NOT_FOUND = -1;

    public static String stripStart(String str, String stripChars) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        int start = 0;
        if (stripChars == null) {
            while ((start != strLen)
                    && Character.isWhitespace(str.charAt(start))) {
                start++;
            }
        } else if (stripChars.length() == 0) {
            return str;
        } else {
            while ((start != strLen)
                    && (stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND)) {
                start++;
            }
        }
        return str.substring(start);
    }
}

Related Tutorials