Write a program to practice how to use
length(), find() and substr() functions. You should understand the first exercise before you try this one.
Follow the steps below:
- Declare a string variable: OriginalString.
- Assign "And now for something completely different."
- Display the length of OriginalString.
- Declare a string variable, srch to store the word "completely "
- Use srch to find the position of "completely " in the OriginalString.
- Display the position of completely.
- Declare a string variable: NewString.
- Use the substr() function to get this sub-string of OriginalString: "And now for something ".
then assign it to NewString.
- Output NewString.
- Get a sub-string of OriginalString with value "different.".
Add this substring to NewString.
- Display NewString. The output should look like this:
And now for something different.
- Compile and run this C++ program.
- Show your lab instructor the program output.
TIPS: Use the position and length of srch to complete the sub-string instructions in your program.
Copyright: Department of Computer Science, University of Regina.