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
🌐
Baeldung
baeldung.com › home › java › java string › get substring from string in java
Get Substring from String in Java | Baeldung
July 21, 2024 - In this quick tutorial, we’ll focus on the substring functionality of Strings in Java. We’ll mostly use the methods from the String class and few from Apache Commons’ StringUtils class. In all of the following examples, we’re going to using this simple String:
🌐
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.
🌐
Tabnine
tabnine.com › home page › code › java › org.apache.commons.lang3.stringutils
org.apache.commons.lang3.StringUtils.substring java code examples | Tabnine
public void updateLabel(Map<CaseInsensitiveString, String> namedRevisions, int pipelineCounter) { this.label = interpolateLabel(namedRevisions, pipelineCounter); this.label = StringUtils.substring(label, 0, 255); }
🌐
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...
🌐
imalittletester
imalittletester.com › 2016 › 07 › 14 › extracting-substrings-with-stringutils-from-the-apache-library
Extracting substrings with StringUtils from the Apache library | imalittletester
June 22, 2019 - Following on from some of my earlier ... a bit on the StringUtils class. As the name suggests, it provides developers and testers an easy way to deal with certain String related operations. The class is quite large, so in this post I will cover the ‘substring’ categ...
🌐
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!"; int length = originalString.length(); String substring = StringUtils.substring(originalString, length - 5, length); // Result: "world" Example 3: Handle null or empty strings gracefully
🌐
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, 2) = "ab" StringUtils.substring("abc", 2, 0) = "" StringUtils.substring("abc", 2, 4) = "c" StringUtils.substring("abc", 4, 6) = "" StringUtils.substring("abc", 2, 2) = "" ...
Find elsewhere
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › java-stringutils-substringsbetween
What is StringUtils.substringsBetween() in Java? - GeeksforGeeks
December 28, 2023 - In this example, we will print ... curly braces using // StringUtils library String[] substrings = StringUtils.substringsBetween( input, "{", "}"); // Loop through each extracted substring and print // it for (String substring ...
🌐
Know Program
knowprogram.com › home › java stringutils substring() method
Java StringUtils substring() Method - Know Program
October 9, 2022 - Let us see an example of the public ... than the,,, sword...!"; System.out.println("The substring is:" + StringUtils.substringAfterLast(str, 9)); System.out.println("The substring is:" + StringUtils.substringAfterLast(str, ",")); ...
🌐
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)
StringUtils.substringBeforeLast(null, *) = null StringUtils.substringBeforeLast("", *) = "" StringUtils.substringBeforeLast("abcba", "b") = "abc" StringUtils.substringBeforeLast("abc", "c") = "ab" StringUtils.substringBeforeLast("a", "a") = "" StringUtils.substringBeforeLast("a", "z") = "a" ...
🌐
LambdaTest
lambdatest.com › automation-testing-advisor › php › methods › common.StringUtils.substring
Use StringUtils.substring in Cucumber Common Library with Examples | LambdaTest
substring after the first occurrence of a separator.860 *861 * The separator is not returned.862 *863 * A `null` `string` input will return `null`.864 * An empty (`''`) `string` input will return the empty `string`.865 * A `null` separator will ...
🌐
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.)
StringUtils.substring(null, *, *) = null StringUtils.substring("", * , *) = ""; StringUtils.substring("abc", 0, 2) = "ab" StringUtils.substring("abc", 2, 0) = "" StringUtils.substring("abc", 2, 4) = "c" StringUtils.substring("abc", 4, 6) = "" StringUtils.substring("abc", 2, 2) = "" ...
🌐
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)
StringUtils.substringBeforeLast(null, *) = null StringUtils.substringBeforeLast("", *) = "" StringUtils.substringBeforeLast("abcba", "b") = "abc" StringUtils.substringBeforeLast("abc", "c") = "ab" StringUtils.substringBeforeLast("a", "a") = "" StringUtils.substringBeforeLast("a", "z") = "a" ...
🌐
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 ...
🌐
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"
🌐
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 ...