Problem 44313. "Cody" * 5 == "CodyCodyCodyCodyCody"

Created by Peng Liu in Community

Alice: What? "Cody" * 5 == "CodyCodyCodyCodyCody"? You've gotta be kidding me!

Bob: No, I am serious! Python supports such "multiplication" of strings, which actually means replication of strings!

Alice: Really?

Bob: Modern languages (C++, Java, Python, etc) tend to use native operators (via overloading) to perform simple string manipulations, such as + for string concatenation (e.g., "Cody" + "Cody" == "CodyCody"). Also, Python adopts * to perform string replication. Since R2016b, MATLAB has followed the same convention by introducing the + operator to perform string concatenation (See Problem 43663 for a Cody example). Nevertheless, as of R2017b, there is no support for the * operator (or any other operators) which performs string replication in MATLAB.

Alice: Sounds like there is a gap...

Bob: You got it. Now, I'd like you to fill the gap by using whatever method (preferably overloading) to make * perform string replication in Cody (similar to * in Python), e.g.,

>> "Cody" * 2
ans = 
>> 3 * "Cody"
  ans = 

Alice: Gotcha. Let me give it a try.

Solution Stats

23.53% Correct | 76.47% Incorrect
Last solution submitted on Mar 07, 2019

Problem Comments

Solution Comments

Recent Solvers187

Suggested Problems

More from this Author43

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!