Bird
0
0

Why does strrep('abcabc', 'abc', 'x') return 'xx' instead of 'xabc' or 'abcx'?

hard📝 Conceptual Q10 of 15
MATLAB - String Handling
Why does strrep('abcabc', 'abc', 'x') return 'xx' instead of 'xabc' or 'abcx'?
Astrrep replaces only the first occurrence
Bstrrep replaces overlapping occurrences causing partial replacements
Cstrrep replaces all non-overlapping occurrences from left to right
Dstrrep replaces only the last occurrence
Step-by-Step Solution
Solution:
  1. Step 1: Understand strrep replacement logic

    strrep replaces all non-overlapping matches from left to right.
  2. Step 2: Apply to 'abcabc'

    Two 'abc' substrings are replaced by 'x' each, resulting in 'xx'.
  3. Final Answer:

    strrep replaces all non-overlapping occurrences from left to right -> Option C
  4. Quick Check:

    Non-overlapping replacement = 'xx' [OK]
Quick Trick: strrep replaces all non-overlapping matches fully [OK]
Common Mistakes:
  • Thinking replacements overlap
  • Assuming partial replacements
  • Expecting only first or last replaced

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes