Is there a function in C# that returns x times of a given char or string? Or must I code it myself?
The Enumerable. Repeat() function of LINQ can be used to repeat a string to a specified number of times in C#. The Enumerable. Repeat() function takes two parameters, a string variable and the number of times that string variable must be repeated.
Java has a repeat function to build copies of a source string: String newString = "a". repeat(N); assertEquals(EXPECTED_STRING, newString);
string.Join("", Enumerable.Repeat("ab", 2));
Returns
"abab"
And
string.Join("", Enumerable.Repeat('a', 2))
Returns
"aa"
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