Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeating a string using StringBuilder

I want to repeat .- 40 times and save it to a string using StringBuilder

Why does this not work?

string result = new StringBuilder("").Append(".-",0,40).ToString();

I know about other Solutions but i want to use StringBuilder

like image 641
c0rd Avatar asked Dec 21 '25 01:12

c0rd


1 Answers

That method does not do what you think it does. The 2 int parameters specify the start index and length of the sub-string you want to append.

StringBuilder does have a method for what you want: It's called Insert:

sb.Insert(0, ".-", 40);
like image 170
Dennis_E Avatar answered Dec 23 '25 14:12

Dennis_E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!