CharSequenceScanner extends AbstractCharStreamScannerImpl { public String getReplaced(String substitute, int start, int end) { int restLength = this.limit - end; StringBuilder builder = builder(null); builder.append(this.buffer, this.initialOffset, start); builder.append(substitute); builder.append(this.buffer, this.initialOffset + end, restLength); return builder.toString(); } CharSequenceScanner(CharSequence charSequence);  CharSequenceScanner(String string);  CharSequenceScanner(char[] characters);  CharSequenceScanner(char[] characters, int offset, int length); char charAt(int index); int getLength(); String substring(int start, int end); String getReplaced(String substitute, int start, int end); @Deprecated void appendSubstring(StringBuffer appendable, int start, int end); void appendSubstring(StringBuilder appendable, int start, int end); int getCurrentIndex(); void setCurrentIndex(int index); @Override boolean hasNext(); @Override char next(); @Override char forceNext(); @Override char peek(); @Override char forcePeek(); String peek(int count); void stepBack(); @Override String readUntil(CharFilter filter, boolean acceptEot); @Override boolean expectStrict(String expected, boolean ignoreCase); @Override void require(String expected, boolean ignoreCase); @Override String readWhile(CharFilter filter, int max); String getOriginalString();  }
@Test public void testGetReplaced() { String start = "hello "; String middle = "world"; String end = " this is cool!"; CharSequenceScanner parser = new CharSequenceScanner(start + middle + end); String middleNew = "universe"; String replaced = parser.getReplaced(middleNew, start.length(), start.length() + middle.length()); assertThat(replaced).isEqualTo(start + middleNew + end); }