Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public static int CountOccurrences(string[] words, string word)
  2. {
  3. int count = 0;
  4. for (int i = 0; i < words.Length; i++)
  5. {
  6. if (String.Compare(word, words[i]) == 0)
  7. {
  8. count++;
  9. }
  10. }
  11. return count;
  12. }
  13. /// <summary>
  14. /// Counts all the occurrences of all the unique words
  15. /// </summary>
  16. /// <param name="text">Whole text</param>
  17. /// <param name="uniqueWords">All unique words</param>
  18. /// <param name="punctuation">Punctuation</param>
  19. /// <returns></returns>
  20. public static int[] UniqueWordsOccurrences(string text, string[] uniqueWords, char[] punctuation)
  21. {
  22. string[] words = text.Split(punctuation);
  23. int[] occurrences = new int[uniqueWords.Length];
  24. for (int i = 0; i < occurrences.Length; i++)
  25. {
  26. occurrences[i] = CountOccurrences(words, uniqueWords[i]);
  27. }
  28. return occurrences;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement