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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:21:35+00:00 2026-06-12T01:21:35+00:00

i am working on simple application which select the file and read that text

  • 0

i am working on simple application which select the file and read that text file and i want to delete all lines which start with `#comments line and here is code

 private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                OpenFileDialog fdlg = new OpenFileDialog();
                fdlg.Title = ".txt File Detector";
                fdlg.InitialDirectory = @"c:\";
                fdlg.Filter = "txt files (*.txt)|*.txt";
                fdlg.FilterIndex = 2;
                fdlg.RestoreDirectory = true;
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    input = fdlg.FileName;
                    textBox1.Text = fdlg.FileName;
                }
            }
            catch (Exception eee)
            {
                MessageBox.Show(eee.ToString());
            }
            string taxt = File.ReadAllText(input);
            string[] lines = new string[100000];
            //string taxt = File.ReadAllText(input);
          while(  taxt != null)
            {

            int count = 0;

                if (taxt.Trim().StartsWith("#") != true)
                {

                    lines[count] = taxt;
                    richTextBox1.Text += lines.ToString();
                    count++;
                }        


            }

i also tried to do with Regular expression as delimeter but that doesn’t work where regex for comments line which start with # is :

“@^#”
and after removing these comments line i want to store in arraylist

  • 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-12T01:21:36+00:00Added an answer on June 12, 2026 at 1:21 am

    Your code has a number of problems:

    • You’re reading the whole file into a single string, so you’re not actually looping over lines
    • You’re looping while taxt is non-null, but never changing its value
    • You’re calling string[].ToString on each iteration, for no obvious reason

    You want something like:

    richTextBox1.Lines = File.ReadLines(input)
                             .Where(line => !line.TrimStart().StartsWith("#"))
                             .ToArray();
    

    However, you shouldn’t be doing the file handling in the UI thread. Do you actually want to show the result in a RichTextBox, or was that just for debugging?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on python, i want to develop some simple web application which
I have developed a simple location aware iPhone application which is functionally working very
Well, simple question. I'm working with VS2008 on an ASP.NET web application which has
I'm working on a simple application that draws an alpha-blended picture on the screen's
I'm working on a simple application with text animations and videos as background. It's
I am working on an application which uploads the content of the file to
HI, I have simple application which copy text from a textbox and paste it
I'm trying to write a simple winforms application that executes a SQL SELECT statement
I am working on a simple standalone desktop application which would generate report based
I am working on a simple application in which I need send sms programmatically

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.