Question
Inputs: (char) A sentence to be modified (char) The word to be replaced in the sentence (char) The word to replace with Outputs: 1. (char)
Inputs:
-
(char) A sentence to be modified
-
(char) The word to be replaced in the sentence
-
(char) The word to replace with
Outputs:
1. (char) Modified sentence Banned Functions:
strrep()
Background:
The ctrlF and replace feature on your laptop is broken and you need to use MATLAB to do the job!
Function Description:
Your function will replace one word within your sentence with another, indicated by your input variables. Your output will be the entire modified sentence with the replaced word.
Example:
original = 'My favorite class is physics!'; wordFind = 'physics'; wordReplace = 'CS1371'; out = repWord(original, wordFind, wordReplace); out 'My favorite class is CS1371!'
Notes:
-
There will be exactly one instance of the word you will replace (it will not appear twice in a sentence)
-
Your function should be case sensitive (i.e. 'MATLAB' and 'matlab' are not the same)
Hints:
-
The strfind() function will be useful!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started