Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:52:11+00:00 2026-05-26T18:52:11+00:00

My question for today is: How can I make function that could find all

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:52:11+00:00Added an answer on May 26, 2026 at 6:52 pm
    if(match.Success && (match.Length > struct.dlugosc))
    

    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:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    using System.Text.RegularExpressions;
    
    namespace Word_Ending_Finder
    {
        public partial class Form1 : Form
        {
            private List<string> WordsToFind = new List<string>();
            private List<MySpecialStringStruct> PassagesToSearch = new List<MySpecialStringStruct>();
    
            public Form1()
            {
                InitializeComponent();
                PassagesToSearch.Add(new MySpecialStringStruct("This is a test passage with a test ending.", 0));
                PassagesToSearch.Add(new MySpecialStringStruct("This is a second test passage with a test ending.", 0));
                PassagesToSearch.Add(new MySpecialStringStruct("This is a third passage that won't match.", 0));
    
                WordsToFind.Add(@"ing\b");
                WordsToFind.Add(@"\bsecond\b");
                WordsToFind.Add(@"\bgarbage text\b");
            }
    
            private void bnGo_Click(object sender, EventArgs e)
            {
                txtResults.Text = "";
                string Separator = "------------------------------------------";
    
                StringBuilder NewText = new StringBuilder();
                foreach (string SearchWord in WordsToFind)
                {
                    NewText.AppendLine(string.Format("Now searching {0}", SearchWord));
                    List<MatchValue> Results = FindPassages(PassagesToSearch, SearchWord);
                    if (Results.Count == 0)
                    {
                        NewText.AppendLine("No Matches Found");
                    }
                    else
                    {
                        foreach (MatchValue ThisMatch in Results)
                        {
                            NewText.AppendLine(string.Format("In passage \"{0}\":", ThisMatch.WhichStringStruct.Passage));
                            foreach (Match M in ThisMatch.MatchesFound)
                            {
                                NewText.AppendLine(string.Format("\t{0}", M.Captures[0].ToString()));
                            }
                        }
                    }
                    NewText.AppendLine(Separator);
                }
    
                txtResults.Text = NewText.ToString();
            }
    
            private List<MatchValue> FindPassages(List<MySpecialStringStruct> PassageList, string WhatToFind)
            {
                Regex MatchPattern = new Regex(WhatToFind);
                List<MatchValue> ReturnValue = new List<MatchValue>();
                foreach (MySpecialStringStruct SearchTarget in PassageList)
                {
                    MatchCollection MatchList = MatchPattern.Matches(SearchTarget.Passage);
                    if (MatchList.Count > 0)
                    {
                        MatchValue FoundMatchResult = new MatchValue();
                        FoundMatchResult.WhichStringStruct = SearchTarget;
                        FoundMatchResult.MatchesFound = MatchList;
                        ReturnValue.Add(FoundMatchResult);
                    }
                }
                return ReturnValue;
            }
        }
    
        public class MatchValue
        {
            public MySpecialStringStruct WhichStringStruct;
            public MatchCollection MatchesFound;
        }
    
        public struct MySpecialStringStruct
        {
            public string Passage;
            public int Id;
    
            public MySpecialStringStruct(string passage, int id)
            {
                Passage = passage;
                Id = id;
            }
        }
    }
    

    The output:

    Now searching ing\b
    In passage "This is a test passage with a test ending.":
    ing
    In passage "This is a second test passage with a test ending.":
    ing
    ------------------------------------------
    Now searching \bsecond\b
    In passage "This is a second test passage with a test ending.":
    second
    ------------------------------------------
    Now searching \bgarbage text\b
    No Matches Found
    ------------------------------------------
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(second question today - must be a bad day) I have a dataframe with
I was asked this question today by a colleague, and couldn't find any clue
Checking out AppHarbor today. My primary question is in the title, but I have
I have window with some STATIC labels and BUTTONs on it. I make all
We have a question we ask at our office during interviews that goes like
I have been asked this question today. When debugging, there is an error. But
How going, dudes? So today it's a really ridiculous question, but i just can't
EDIT question to make it understandable . Today I tried to do a programm
I am serious getting bogged down by various technologies that's available today. For example,
I ran into an interesting issue today. I have canvas elements that I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.