I am building up a string of data using substring. The format of the data I want is
[1,2,3,4,5,6,7,8,9,10]
So I am building it up as follows
StringBuilder sb = new StringBuilder();
sb.append("1,");
sb.append("2,");
sb.append("3,");
.
.
.
The problem I run into is when I want to trim the final ,
before adding the closing ]
.
I could do
sb.ToString();
sb.Substring(0, (sb.Length - 1));
sb += "]";
But using the += is not very efficient as this creates a new string. Is there a better way of doing this?