StringBuilder huge string concatenation
-
We are building a html(some controls) and assigning to a div's innerhtml. They are built using some validations. The size of the string in any case would be around 200 KB(The controls are more). We are calling one or two functions in a loop which is returning a stringbuilder. The calling function will append the return value to a main stringbuilder. Main stringbuilder will be around 200 KB and the stringbuilder within functions will be around 100bytes. Will that be a better way to initialize the stringbuilder with some expected values. Thanks, K.P.Kannan
-
We are building a html(some controls) and assigning to a div's innerhtml. They are built using some validations. The size of the string in any case would be around 200 KB(The controls are more). We are calling one or two functions in a loop which is returning a stringbuilder. The calling function will append the return value to a main stringbuilder. Main stringbuilder will be around 200 KB and the stringbuilder within functions will be around 100bytes. Will that be a better way to initialize the stringbuilder with some expected values. Thanks, K.P.Kannan
If you know the size of the StringBuilder I would initialize it with that size or a little more for efficiency but in general StringBuilders are just more efficient as they are. You dont necessarily have to use "expected values" though.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)