Skip to content

Commit

Permalink
Adding StringUtil#substringBetween
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Nov 19, 2024
1 parent 76fb487 commit 4b07e29
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.stream.Stream;

/**
* String Utilities.
Expand Down Expand Up @@ -612,4 +614,22 @@ public static String join(final Object[] array, final char separator, final int
}
return buf.toString();
}

public static boolean allNotNull(final Object... values) {
return values != null && Stream.of(values).noneMatch(Objects::isNull);
}

public static String substringBetween(final String str, final String open, final String close) {
if (!allNotNull(str, open, close)) {
return null;
}
final int start = str.indexOf(open);
if (start != -1) {
final int end = str.indexOf(close, start + open.length());
if (end != -1) {
return str.substring(start + open.length(), end);
}
}
return null;
}
}

0 comments on commit 4b07e29

Please sign in to comment.