If there is no repetition of given substring then try this.
String s ="123456789";
s = s.replace(s.substring(3,6), "foobar");
If there is repetition of given substring then try this.
String s ="123123123";
s= s.substring(0,3) + "foobar" + s.substring(6,s.length());