문제

I need to extract the first line of many huge StringBuilders(around 1mb of data each) in a loop. To do so, I thought about doing this:

string header;
foreach(StringBuilder strBuilder in bigArray)
    header= strBuilder.ToString().SubString(blabla);

but I'm worried the .ToString() method might take too long to execute. Do you have any idea about how I can do this efficiently?

도움이 되었습니까?

해결책

If you're looking for a Substring alternative that doesn't extract the entire string from the StringBuilder you could use the overload of ToString that takes a start and length:

string header;
foreach(StringBuilder strBuilder in bigArray)
{
    header= strBuilder.ToString(start, length);
}

Is it faster? I don't know - you'll have to measure it to know for sure.

Another alternative would be to store the "lines" as a collection of string arrays (or List<List<string>>) rather than a collection of StringBuilders.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top