/* File: EditableString.java Developed for Problem Solving with Java, Koffman & Wolz Appears in Figure 5.18 */ public class EditableString { // Data fields private String text; // string being edited // Methods public void setText(String s) { text = s; } // Searches editString for a target string. public int search(String target) { int index = text.indexOf(target); return index; } // Inserts a substring in editString. public String insert(String newString, int index) { // Join string before index, newString, and // string after index. text = text.substring(0, index) + newString + text.substring(index); return text; } // Deletes a substring of editString. public String delete(String oldString) { // ... return text; } // Replaces one substring of editString (oldString) with another (newString). public String replace(String oldString, String newString) { // ... return text; } public String toString() { return text; } } // class EditableString