i'm trying to parse 130,000 document , and i'm trying to do that as fast as i can.
this function is for removing the delimiter char in Document.
public static unsafe string StripRestAndNewlines(string s)
{
int len = s.Length;
char* newChars = stackalloc char[len];
char* currentChar = newChars;
for (int i = 0; i < len; ++i)
{
char c = s[i];
switch (c)
{
case ',':
case '.':
case ':':
case ';':
case '-':
case '>':
case '<':
case '/':
case '\\':
case '?':
case '"':
case '*':
case '&':
case '_':
case '+':
case '@':
case '[':
case ']':
case '!':
case '=':
case '%':
case '#':
continue;
default:
*currentChar++ = c;
break;
}
}
return new string(newChars, 0, (int)(currentChar - newChars));
}
but after 2 min of running the program stop and i'm getting
system.StackOverflowException
is there any delete[] of free for the allocate?
thanks!