1
Answer

C# equivalent for appendReplacement in java

Jans

Jans

18y
3.1k
1
Is there any C# equivalent code for the appendReplacement  functionality in JAVA. I guess no! but could anyone help me to get it?

Java Code:
Pattern p = Pattern.compile("cat");
Matcher m = p.matcher("one cat two cats in the yard");
StringBuffer sb = new StringBuffer();
while (m.find()) {
     m.appendReplacement(sb, "dog");
}
m.appendTail(sb);
System.out.println(sb.toString());

O/P: one dog two dogs in the yard
Answers (1)