String foo = "<foo>foo</foo>";
String bar = StringUtils.substringBetween(foo, "<foo>", "</foo>");
The variable bar will have the String "foo".
Answer from Ramon Saraiva on Stack Overflow Top answer 1 of 6
22
String foo = "<foo>foo</foo>";
String bar = StringUtils.substringBetween(foo, "<foo>", "</foo>");
The variable bar will have the String "foo".
2 of 6
6
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("", "[", "]") = []
Educative
educative.io › answers › what-is-the-stringutilssubstring-method-in-java
What is the StringUtils.substring() method in Java?
Line 1: We import the StringUtils class. Line 6: We define the text or the string called text. Line 7: We define the starting index called start. Line 8: We define the ending index called end.
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.20.0 API)
StringUtils.abbreviate("abcdefghijklmno", 8, 10) = "...ijklmno" StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno" StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno" StringUtils.abbreviate("abcdefghij", 0, 3) = IllegalArgumentException StringUtils.abbreviate("ab...
Hotexamples
java.hotexamples.com › examples › org.apache.commons.lang › StringUtils › substring › java-stringutils-substring-method-examples.html
Java StringUtils.substring Examples, org.apache.commons.lang.StringUtils.substring Java Examples - HotExamples
import org.apache.commons.lang.StringUtils; String originalString = "Hello world!"; String substring = StringUtils.substring(originalString, 0, 3); // Result: "Hel" Example 2: Get the last 5 characters of a string
Java2s
java2s.com › Tutorial › Java › 0500__Apache-Common › StringUtilssubstring.htm
StringUtils.substring : StringUtils « Apache Common « Java Tutorial
StringUtils.substring : StringUtils « Apache Common « Java Tutorial
AWS
sdk.amazonaws.com › java › api › latest › software › amazon › awssdk › utils › StringUtils.html
StringUtils (AWS SDK for Java - 2.42.6)
StringUtils.substring(null, *) = null StringUtils.substring("", *) = "" StringUtils.substring("abc", 0) = "abc" StringUtils.substring("abc", 2) = "c" StringUtils.substring("abc", 4) = "" StringUtils.substring("abc", -2) = "bc" StringUtils.substring("abc", -4) = "abc"
Eduardo Figueiredo
homepages.dcc.ufmg.br › ~andrehora › examples › org.apache.commons.lang3.StringUtils.substringBefore.11.html
org.apache.commons.lang3.StringUtils.substringBefore
StringUtils.substringBefore(null, *) = null StringUtils.substringBefore("", *) = "" StringUtils.substringBefore("asdfg", null)) = "asdfg" StringUtils.substringBefore("asdfg", "a")) = "" StringUtils.substringBefore("asdfg", "sd")) = "a" StringUtils.substringBefore("asdfsag", "sa")) = "asdf" StringUtils.substringBefore("asdfg", "h")) = "asdfg" StringUtils.substringBefore("asdfg", "")) = "" StringUtils.substringBefore("asdfg", "dfgh")) = "asdfg" StringUtils.substringBefore("asdfg", "dfg")) = "as" StringUtils.substringBefore("abbbabbba", "bb")) = "a" public static MarkPos fromString(@Nullable Stri
Spring
docs.spring.io › spring-framework › docs › current › javadoc-api › org › springframework › util › StringUtils.html
StringUtils (Spring Framework 7.0.5 API)
Strip the filename extension from the given Java resource path, for example, "mypath/myfile.txt" → "mypath/myfile". ... Test whether the given string matches the given substring at the given index.
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.6 › org › apache › commons › lang › StringUtils.html
StringUtils (Commons Lang 2.6 API)
A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the empty string if the input string is not null. If nothing is found, the empty string is returned. StringUtils.substringAfterLast(null, *) = null ...
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › 6-5 › javadoc › org › apache › commons › lang › StringUtils.html
StringUtils (The Adobe AEM Quickstart and Web Application.)
A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the empty string if the input string is not null. If nothing is found, the empty string is returned. StringUtils.substringAfterLast(null, *) = null ...
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.3 › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.3 API)
A null string input will return null. An empty ("") string input will return the empty string. An empty or null separator will return the empty string if the input string is not null. If nothing is found, the empty string is returned. StringUtils.substringAfterLast(null, *) = null ...
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-release › org › apache › commons › lang3 › StringUtils.html
StringUtils (Apache Commons Lang 3.11 API)
Instead, the class should be used as StringUtils.trim(" foo ");. This constructor is public to permit tools that require a JavaBean instance to operate. public static String abbreviate(String str, int maxWidth) Abbreviates a String using ellipses. This will turn "Now is the time for all good ...
Apps Developer Blog
appsdeveloperblog.com › home › java › java examples › get substring from string in java
Get Substring from String in Java - Apps Developer Blog
August 16, 2022 - substringBetween(String str, String open, String close) – Gets the String that is nested in between two Strings. import org.apache.commons.lang3.StringUtils; public class Test { public static void main(String[] args) { String str = "Hello, my name is Tom, and I live in USA"; String ...
AWS
sdk.amazonaws.com › java › api › 2.1.3 › software › amazon › awssdk › utils › StringUtils.html
StringUtils (AWS SDK for Java - 2.1.3)
StringUtils.substring(null, *) = null StringUtils.substring("", *) = "" StringUtils.substring("abc", 0) = "abc" StringUtils.substring("abc", 2) = "c" StringUtils.substring("abc", 4) = "" StringUtils.substring("abc", -2) = "bc" StringUtils.substring("abc", -4) = "abc"