Get sub String Between start and end - Android java.lang

Android examples for java.lang:String Substring

Description

Get sub String Between start and end

Demo Code

public class Main {

  public static String subStringBetween(String source, String start, String end) {
    if (source == null || start == null || end == null) {
      return null;
    }/*from   w w  w .  ja v a 2s .  c  om*/
    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