i am a little unsure of the code iv'e written as...
im pretty noob with the stringbuilder class
my app will rely on as few gc collections as possible text can be a problem
but i have specific problem were
i need to pull appended lines from a stringbuilder object
put it into a list or array of stringbuilders
keep the original and modify the list elements lengths to shorten them
the real problem is im unsure if this is ok what im doing
or if there is a better way already
public static List
{
List
sb_list.Add(new StringBuilder());
char line_break_char = '\n';
if (false == char.TryParse(Environment.NewLine, out line_break_char)) { line_break_char = '\n'; }
//
int sbli = 0;
for (int i = 0; i < sb_text.Length; i++)
{
if (sb_text[i].CompareTo(line_break_char) != 0)
{
sb_list[sbli].Append(sb_text[i]);
}
else
{
sb_list.Add(new StringBuilder());
sbli++;
}
}
return sb_list;
}
VulpesPosted Apr 14, 2014, 10:59 AM
Although these things are to some extent a matter of taste, I'd have done it like this: