Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BruteForce : ISubstringSearch
- {
- public BruteForce()
- {
- }
- public List<int> Search(string fileName, string searchString)
- {
- List<int> result = new List<int>();
- int M = searchString.Length;
- using (StreamReader sr = new StreamReader(fileName))
- {
- string line = sr.ReadLine();
- int N = line.Length;
- for (int i = 0; i < N-M; i++)
- {
- for (int j = 0; j < M; j++)
- {
- if (line[i + j] == searchString[j])
- {
- if(j == M - 1)
- {
- result.Add(i);
- }
- }
- else { break; }
- }
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement