Question: Write the replaceOne method. replaceOne(text, i, n, sub) replaces a segment of text of length n that starts at index i with the replacement string
-
Write the replaceOne method. replaceOne(text, i, n, sub) replaces a segment of text of length n that starts at index i with the replacement string sub. (The length of sub is not necessarily the same as the length n of the segment to be replaced). replaceOne returns the modified text. Complete the method replaceOne below.
Question 1(a)
-
/** Replaces several characters in a given text string, * starting at a given index, with a new substring. * @param text string to be modified, * @param i starting index of replacement * @param n number of characters to be replaced * @param sub replacement string * @return modified text * Precondition: i + n <= text.length() */ public static String replaceOne(String text, int i, int n, String sub)
-
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
