I need to count the lines in one very free line (about 30 MB in text form) I use the following code:
int count = new Regex(Regex.Escape(stringThatIamLookingFor)).Matches(stringToSearchIn).Count;
but it is too slow. It takes about 3 minutes on i7 and 16gb RAM. Examples are:
43.996442,-31.768039
43.996432,-31.768039
43.996432,-31.768049
43.996422,-31.768049
43.996422,-31.768059
I want to count (for example) .7
Is there a faster way than regeex?
ok, solved
The fastest function so far: (I need to check only two characters.)
public int countOccurences2(string source, char charOne, char charTwo)
{
int count = 0;
for (int i=0; i<=source.Length-1; i=i+2)
if (source[i] == charOne && source[i + 1] == charTwo) { count++; }
return count;
}
source
share