Kactoos

kactoos-jvm / nnl.rocks.kactoos.text / ReplacedText

ReplacedText

class ReplacedText : TextEnvelope

Replace the Text.

The given regex is used to produce a matcher that will be transformed by func into a replacement string to replace each matching substring.

Example usage:

final String result = new ReplacedText(
new TextOf("one two THREE four FIVE six"),
() -> Pattern.compile("[a-z]+"),
matcher -> String.valueOf(matcher.group().length())
).asString();  //will return the string "3 3 THREE 4 FIVE 3"

Note: a PatternSyntaxException will be thrown if the regular expression’s syntax is invalid.

Since 0.2

Constructors

Name Summary
<init> ReplacedText(origin: Text, regex: KScalar<Pattern>, replacement: Func<Matcher, String>)ReplacedText(text: Text, find: String, replace: String)
Will replace all instances of the substring matched by find with replace.

Inherited Functions

Name Summary
asString open fun asString(): String
Convert it to the string.
compareTo open fun compareTo(other: Text): Int
equals open fun equals(other: Any?): Boolean
hashCode open fun hashCode(): Int
toString open fun toString(): String