I have a very long string (60MB in size) in which I need to find how many pairs of \'<\' and \'>\' are in there.
I have first tried my own way:
Using a switch statement instead of an if test speeds things up a little also. This code occasionally beats the indexof code on my machine.
int count = 0;
bool open = false;
for (int j = 0; j < testStr.Length; j++)
{
switch (testStr[j])
{
case '<':
open = true;
break;
case '>':
if (open)
count++;
open = false;
break;
}
}