Makes a new utility class containing methods related to strings
This commit is contained in:
parent
2c3e37d46c
commit
a5e14b4ee5
@ -0,0 +1,28 @@
|
|||||||
|
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 <p>The string containing the substrings.</p>
|
||||||
|
* @param start <p>The substring before the wanted substring.</p>
|
||||||
|
* @param end <p>The substring after the wanted substring.</p>
|
||||||
|
* @return <p>A list of all occurrences of the substring.</p>
|
||||||
|
*/
|
||||||
|
static String[] stringBetween(String string, String start, String end) {
|
||||||
|
int startPos = string.indexOf(start) + start.length();
|
||||||
|
if (!string.contains(start) || string.indexOf(end, startPos) < startPos) {
|
||||||
|
return new String[]{};
|
||||||
|
}
|
||||||
|
int endPos = string.indexOf(end, startPos);
|
||||||
|
String outString = string.substring(startPos, endPos).trim();
|
||||||
|
String nextString = string.substring(endPos + end.length());
|
||||||
|
return ListUtil.concatenate(new String[]{outString}, stringBetween(nextString, start, end));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user