Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int CountOccurrences(string[] words, string word)
- {
- int count = 0;
- for (int i = 0; i < words.Length; i++)
- {
- if (String.Compare(word, words[i]) == 0)
- {
- count++;
- }
- }
- return count;
- }
- /// <summary>
- /// Counts all the occurrences of all the unique words
- /// </summary>
- /// <param name="text">Whole text</param>
- /// <param name="uniqueWords">All unique words</param>
- /// <param name="punctuation">Punctuation</param>
- /// <returns></returns>
- public static int[] UniqueWordsOccurrences(string text, string[] uniqueWords, char[] punctuation)
- {
- string[] words = text.Split(punctuation);
- int[] occurrences = new int[uniqueWords.Length];
- for (int i = 0; i < occurrences.Length; i++)
- {
- occurrences[i] = CountOccurrences(words, uniqueWords[i]);
- }
- return occurrences;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement