My question for today is:
How can I make function that could find all words matching the pattern?
For example we have word: duck and we want find all words starting from that word duck.
I am looking for best perfomance function, I would be glad if it could be using LINQ.
So far I made something like that (it doesn’t work yet):
public List<List<string>> FindWordsPostfix(List<Parameters.Words> wordsChess, List<string> wordsFromDictionary, int width)
{
List<List<string>> listPostfixForstructxIndex = new List<List<string>>();
foreach (Parameters.Words structx in wordsChess)
{
//1for each structx I have some parameters eg. name, length, index
//2for each word (name) I need find word from dict. starting that word(name)
//list storing lists of words for each of the structx object
List<string> list = new List<string>();
foreach (String wordDictionary in wordsFromDictionary)
{
Match match = Regex.Match(wordDictionary, structx.word, RegexOptions.IgnoreCase);
if(match.Success && (match.Length > structx.length))
{
list.Add(match.Value);
}
}
//add list of words to main list
listPostfixForstructxIndex.Add(list);
}
throw new NotImplementedException();
}
Parameters.Words is a struct containing: string name, int length, etc...
Why my function is bad and doesn’t storing any data?
PS2. I edited the question. I had to clean up that mess what I did.
The Match’s length is never going to be longer than the struct’s length – the struct’s length at minimum is that of the string, plus all the other items in it.
What else were you testing for after match.Success?
If you want some matching code for what I think you’re asking for, the following works a charm:
The output: