can someone demonstrate how to work with StringUtils.substringsBetween() method in java?
String foo = "<foo>foo</foo>";
String bar = StringUtils.substringBetween(foo, "<foo>", "</foo>");
The variable bar will have the String "foo".
This one? Pretty clear from the JavaDoc:
Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.
A null input String returns null. A null open/close returns null (no match). An empty ("") open/close returns null (no match).
StringUtils.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"] StringUtils.substringsBetween(null, *, *) = null StringUtils.substringsBetween(*, null, *) = null StringUtils.substringsBetween(*, *, null) = null StringUtils.substringsBetween("", "[", "]") = []
String bigString = "Quick brown fox jumps over the lazy dog";
String smallString = org.apache.commons.lang.StringUtils.subStringBetween(bigString, "brown", "the");
System.out.println(smallString);
output -
jumps over
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With