Get sub String Between two index - Android java.lang

Android examples for java.lang:String Substring

Description

Get sub String Between two index

Demo Code


public class Main{

    public static String subStringBetween(String source, String start,
            String end) {//  w w  w .ja  va  2s. c  om
        if (source == null || start == null || end == null) {
            return null;
        }
        int indexOf = source.indexOf(start);
        if (indexOf == -1)
            return null;
        int indexOf2 = source.indexOf(end, start.length() + indexOf);
        return indexOf2 != -1 ? source.substring(start.length() + indexOf,
                indexOf2) : null;
    }

}

Related Tutorials