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 start

The substring before the wanted substring.

* @param end

The substring after the wanted substring.

* @return

A 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)); } }