Here you can find the source of substringBetween(String s, String part1, String part2)
Parameter | Description |
---|---|
s | The String you want to substring. |
part1 | The beginning of the String you want to search for. |
part2 | The end of the String you want to search for. |
public static String substringBetween(String s, String part1, String part2)
//package com.java2s; //License from project: Open Source License public class Main { /**//w w w . j av a 2 s . c om * Returns the first instance of String found exclusively between part1 and part2. * @param s The String you want to substring. * @param part1 The beginning of the String you want to search for. * @param part2 The end of the String you want to search for. * @return The String between part1 and part2. * If the s does not contain part1 or part2, the method returns null. */ public static String substringBetween(String s, String part1, String part2) { String sub = null; int i = s.indexOf(part1); int j = s.indexOf(part2, i + part1.length()); if (i != -1 && j != -1) { int nStart = i + part1.length(); sub = s.substring(nStart, j); } return sub; } }