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 8012225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:15:55+00:00 2026-06-04T19:15:55+00:00

In my C# program (at this point) I have two fields in my form.

  • 0

In my C# program (at this point) I have two fields in my form. One is a word list using a listbox; the other is a textbox. I have been able to successfully load a large word list into the listbox from a text file. I can also display the selected item in the listbox into the textbox this way:

private void wordList_SelectedIndexChanged(object sender, EventArgs e)
     {
          string word = wordList.Text;
          concordanceDisplay.Text = word;
     }

I have another local file I need to get at to display some of its contents in the textbox. In this file each headword (as in a dictionary) is preceded by a #. So, I would like to take the variable ‘word’ and search in this local file to put the entries into the textbox, like so:

#headword1
    entry is here...
    ...
    ...
#headword2
    entry is here...
    ...
    ...
#headword3
    entry is here...
    ...
    ...

You get the format of the text file. I just need to search for the correct headword with # before that word, and copy all info from there until the next hash in the file, and place it in the text box.

Obviously, I am a newbie, so be gentle. Thanks much.

P.S. I used StreamReader to get at the word list and display it in the listbox like so:

StreamReader sr = new StreamReader("C:\\...\\list-final.txt");
       string line;
       while ((line = sr.ReadLine()) != null)
       {
           MyList.Add(line);
       }
       wordList.DataSource = MyList;
  • 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-06-04T19:15:57+00:00Added an answer on June 4, 2026 at 7:15 pm
    string getSection(string sectionName)
    {
        StreamReader sr = new StreamReader(@"C:\Path\To\file.txt");
        string line;
        var MyList = new List<string>();
        bool inCorrectSection = false;
        while ((line = sr.ReadLine()) != null)
        {
            if (line.StartsWith("#"))
            {
                if (inCorrectSection)
                    break;
                else
                    inCorrectSection = Regex.IsMatch(line, @"^#" + sectionName + @"($| -)");
            }
            else if (inCorrectSection)
                MyList.Add(line);
        }
        return string.Join(Environment.NewLine, MyList);
    }
    
    // in another method
    textBox.Text = getSection("headword1");
    

    Here are a few alternate ways to check if the section matches, in rough order of how accurate they are in detecting the right section name:

    // if the separator after the section name is always " -", this is the best way I've thought of, since it will work regardless of what's in the sectionName
    inCorrectSection = Regex.IsMatch(line, @"^#" + sectionName + @"($| -)");
    // as long as the section name can't contain # or spaces, this will work
    inCorrectSection = line.Split('#', ' ')[1] == sectionName;
    // as long as only alphanumeric characters can ever make up the section name, this is good
    inCorrectSection = Regex.IsMatch(line, @"^#" + sectionName + @"\b");
    // the problem with this is that if you are searching for "head", it will find "headOther" and think it's a match
    inCorrectSection = line.StartsWith("#" + sectionName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using cython for a correlation calculation in my python program. I have two
I have a form in CakePHP that has two live-search text input. Each one
I have a program like this : import re x='aaaaaaaa;aa;aaa;aaa;aaaaaaaaaa;' x=re.sub(';','.',x, re.IGNORECASE) print x
I've been reading two articles (1) (2) on javaworld.com about how all class fields
I have this two functions: procedure TDisplay.CubAssign(VAR Obj: TCubObj; CONST bReleaseOnExit: boolean); begin ReleaseCubOnExit:=
Could you guys please point what I'm missing here ? I have two sample
I'm creating Win32 application and I have two projects. The first one is a
I have a program that load data from a file using std::ifstream and store
I have two Win32 API programs written in plain C: Program A and program
I am writing a program that will eventually be used to have one child

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.