about | help | code help+videos | done | prefs |
Write a method that replaces each occurrence of 'replace' with 'replacement' starting at the left end of the string, but only up to 'max' number of times. If 'replace' occurs more than 'max' number of times, you do NOT replace those instances of 'replace'. Instead, you keep them in the string. NOTE: You may use a 'while' loop to solve this problem, but you are NOT allowed to use any 'for' loops. The reason for this is that you may need to do something with the loop that you shouldn't do with a 'for' loop. This also might be a little hint! As preconditions you may assume that 'max'>=0. You may NOT assume that 'replace' and 'replacement' are the same length. In fact, they may be different lengths! test2024_12_12_P1SLHL_replace("abcdadefaatlatpaaaweeeeaaa", "a", "", 155) → "bcddeftltpweeee" test2024_12_12_P1SLHL_replace("Notes should be out and open at all times except during quizzes and tests or unless you are specifically told otherwise.", "t", "T", 8) → "NoTes should be ouT and open aT all Times excepT during quizzes and TesTs or unless you are specifically Told otherwise." test2024_12_12_P1SLHL_replace("Notes should be out and open at all times except during quizzes and tests or unless you are specifically told otherwise.", "t", "T", 4) → "NoTes should be ouT and open aT all Times except during quizzes and tests or unless you are specifically told otherwise." ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 280
Copyright Nick Parlante 2017 - privacy