Is there a fast way to append a StringBuilder multiple times in C#? Of course I can write my own extension to append in loop, but it looks ineffective.
There is already an Append overload that accepts char value and int repeatCount:
char c = ...
int count = ...
builder.Append(c, count);
or more simply (in many cases):
builder.Append(' ', 20);
You can use string constructor
sb.Append(new String('a', 3)); // equals sb.Append("aaa")
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