Example:
string input = "super";
string rep = "a";
I want the output same charterers as per given input string
length
. The output should be "aaaaa
".
I dont like to use own FOR or While loops logic, is there any alternatives to accomplish it.
Use the constructor
string output = new string('a', input.Length);
If you want to repeat a real string
n-times, you could use Enumerable.Repeat
:
string output = string.Join("", Enumerable.Repeat(rep, input.Length));
I use String.Join
to concatenate each string with a specified seperator(in this case none).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With