Skip to content

StringUtils.substringAfter

Signature: StringUtils.substringAfter(inputString, separator)

Returns: String result - the substring after the first occurrence of the separator, or null if inputString is null

Gets the substring after the first occurrence of a separator. The separator is not returned. A null inputString will return null. An empty ("") inputString will return the empty string. A null separator will return the empty string if the inputString is not null. If nothing is found, the empty string is returned.

Parameters

Type Name Description Default
String inputString the String to get a substring from, may be null
String separator the String to search for, may be null

Example

// Typical usage: returns text after the FIRST occurrence of the separator (separator not included)
StringUtils.substringAfter("I love to eat apples!", "eat ");     // apples!

// If the separator is not found, returns the empty string
StringUtils.substringAfter("I love to eat apples!", "potato");   // ""

// If inputString is empty, returns empty string (even though nothing can be found)
StringUtils.substringAfter("", "eat ");                          // ""

// If inputString is null, returns null
StringUtils.substringAfter(null, "eat ");                        // null

// If separator is null and inputString is not null, returns empty string
StringUtils.substringAfter("I love to eat apples!", null);       // ""