package net.knarcraft.ffmpegconverter.utility; /** * A class which helps with operations on strings */ final class StringUtil { private StringUtil() { } /** * Finds all substrings between two substrings in a string * * @param string
The string containing the substrings.
* @param startThe substring before the wanted substring.
* @param endThe substring after the wanted substring.
* @returnA list of all occurrences of the substring.
*/ static String[] stringBetween(String string, String start, String end) { int startPosition = string.indexOf(start) + start.length(); //Return if the string is not found if (!string.contains(start) || string.indexOf(end, startPosition) < startPosition) { return new String[]{}; } int endPosition = string.indexOf(end, startPosition); //Get the string between the start and end string String outString = string.substring(startPosition, endPosition).trim(); String nextString = string.substring(endPosition + end.length()); //Add other occurrences recursively return ListUtil.concatenate(new String[]{outString}, stringBetween(nextString, start, end)); } }