c# - Get x number of unique words on each side of a word in a string? -


I am trying to get x number on each side of a word in a string in C #. For example, the method

  GetUniqueWords ("She sells seashells seashers, she sells shells, are definitely seashells.", "Seashore", 3)  < / Pre> 

(The first parameter is the string string. The second parameter is the word that will be used to get the word on two sides. The third parameter is the number of the check number)

Return a list of:

Seashals


shells
that

Thanks in advance

Not good, but working for your sample: -)

  Private Static IEnumerable & lt; String & gt; GetUniqueWords (string phrase, string word, int amount) {// clean string and get word string [] word = Regex.Split (phrase.replace (".", ""). Change (",", " ), @ "\ S +"); // Find the first occurrence of the desired word (allows imagination) int index = Array.IndexOf (words, words); // We do not wrap around the edges if the word is the first, // We will not see before, if we do not see the last time, then, the unit will be allowed int minute = (index - amount & lt; 0) ? 0: Index - amount; Int max = (index + amount & gt; word number) - 1)? Words. Calculation () - 1: Index amount; // Add all the words in a list, except the list & lt; String & gt; RV = new list & lt; String & gt; (); {If (i == index) continues for (int i = mi; i & lt; = max; i ++); Rv.Add (term [i]); } // unique- ify result return list (rv.Distinct); }}  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -