Skip to content

StringUtils.replace

Signature: StringUtils.replace(inputString, searchString, replacement)

Returns: String result - the text with any replacements processed, or null if inputString is null

Replaces all occurrences of the searchString within the inputString with the replacement string. A null reference passed to this method results in no replacement.

Parameters

Type Name Description Default
String inputString text to search and replace in, may be null
String searchString the string to search for, may be null
String replacement the string to replace it with, may be null

Example

StringUtils.replace("\t\tThis is a test!", "\t", "");                   // This is a test!
StringUtils.replace("I like to eat apples and bananas!", "to eat", ""); // I like  apples and bananas!
StringUtils.replace("I like to eat apples and bananas!", "a", "o");     // I like to eot opples ond bononos!