← Back to Strings
Question 301
Swap Cats for Dogs
Swap Cats for Dogs
The Replace method returns a new string in which every occurrence of one piece of text is swapped for another. You call it as text.Replace(oldValue, newValue). You are given a string named sentence set to "I like cats". Use Replace to swap the word "cats" for "dogs" and print the updated sentence. The original string is not modified — Replace hands back a fresh string with the change applied.Expected Output:
I like dogs= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Strings
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.