about | help | code help+videos | done | prefs |
Write a method that accepts three string parameters, 'orig' which is the original string, 'mask' which is to be used as a mask to indicate which characters to replace, and 'replace' which contains the replacement characters. Return a new string that is based on 'orig', but with some of its characters replaced by characters from 'replace'. The 'mask' string is used to determine which characters get replaced. For each "#" character in 'mask', replace the character at the same location in 'orig' with the character in the same location in 'replace'. Ignore all other characters in 'mask'. Only the "#" character triggers a replacement. All three strings can contain any valid string character. In the 'mask' string, the "#" character is a special character used to indicate that a replacement is needed. For each position in the 'mask' string with a "#", replace the character at that location in the 'orig' string with the character from that location in the 'replace' string. For example, if 'orig'="Front", 'mask'="5##j%", and 'replace'="Bains", you would return "Faint". Note that the ONLY character in 'mask' that triggers a replacement is the "#" character. As a precondition, you may assume that all three strings are the same length. Look at the test data for examples. test2023_06_01_APP1SL_replace("A man a plan a canal panama", "a#b#c#d#e#f#g#h#i#j#k#l#m#n", "XXXXXXXXXXXXXXXXXXXXXXXXXXX") → "AXmXnXaXpXaX X XaXaX XaXaXa" test2023_06_01_APP1SL_replace("This is a test", "#_:_:##_:_:#_:", "AAAAAAAAAAAAAA") → "Ahis AA a tAst" test2023_06_01_APP1SL_replace("Summer!", "#######", "Is here") → "Is here" ...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: 250
Copyright Nick Parlante 2017 - privacy