Your answer reads:
I know this is already answered, but while searching for a solution
too for this, I came across this blog, and thought it might be
helpful. The blog benchmarks numerous techniques for testing if a
string contains a string:
Some of the techniques include:
Linq.Contains() and other techniques including parallel methods.
IndexOf, Regex, and Linq were the slowest options.
The fastest was:
for (int x = 0; x < ss.Length; x++)
for (int y = 0; y < sf.Length; y++
c[y] += ((ss[x].Length - ss[x].Replace(sf[y], String.Empty).Length) / sf[y].Length > 0 ? 1 : 0);
where ss is the array of strings to search, sf is the array of strings
to search for.
If anything I would have thought the above code would not be the
fastest because of all the string operations performed (replace,
His code is publicly posted so anyone can test the micro-optimizing on
their own machines.
Makes for an interesting read.
Look at the comment I just posted below the question:
This blog benchmarks numerous techniques for testing if a string contains a string: http://blogs.davelozinski.com/curiousconsultant/csharp-net-fastest-way-to-check-if-a-string-occurs-within-a-string
That's how you should do this.
While your answer does add useful detail to the post, Stack Overflow is a Q&A site, and the question was already definitively answered here, three years ago.
Had the question asked "What is the fastest way to find a string within a string," then your answer would have been definitive.