I have to count string occurences in one very loooong string (about 30mb in plain text)
I use the following code for now:
int count = new Regex(Regex.Escape(stringThatIamLookingFor)).Matches(stringToSearchIn).Count;
but is is too slow. It takes about 3 minutes on i7 and 16gb ram.
The example data is:
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 faster way than regeex?
ok, solved
The fastest function so far is: (I need to check only two chars.)
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;
}