Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. public Dictionary<string, SortedSet<int>> CountStream()
  2.         {
  3.             Dictionary<string, SortedSet<int>> dctWords = new Dictionary<string, SortedSet<int>>();
  4.             string buffer = string.Empty;
  5.            
  6.             foreach (char ch in sToSearch)
  7.             {
  8.                 buffer += ch;
  9.                
  10.                 foreach(string word in lstSearchFor) {
  11.                     int iSearchIndex = 0;
  12.                     while ((iSearchIndex = buffer.IndexOf(word, iSearchIndex)) != -1)
  13.                     {
  14.                         if (!dctWords.ContainsKey(word))
  15.                         {
  16.                             dctWords.Add(word, new SortedSet<int>());
  17.                             dctWords[word].Add(iSearchIndex);
  18.                         }
  19.                         else
  20.                         {
  21.                             if (!dctWords[word].Contains(iSearchIndex))
  22.                                 dctWords[word].Add(iSearchIndex);
  23.                         }
  24.                         iSearchIndex++;
  25.                     }
  26.                 }
  27.             }
  28.             return dctWords;
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement