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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:41:56+00:00 2026-05-25T20:41:56+00:00

Hi I have a text file with table schema and data when user checks

  • 0

Hi I have a text file with table schema and data when user checks not schema required then i need to delete schema and leave the data . I am using StreamReader to read the file and checking one condition and it should delete all the lines in the file till it satisfies my condition .
Let say if i am checking

  using (StreamReader tsr = new StreamReader(targetFilePath))
        {
            do
            {
                string textLine = tsr.ReadLine() + "\r\n";

                {
                    if (textLine.StartsWith("INSERT INTO"))
                    {

                         // It should leave these lines 
                        // and no need to delete lines 
                    }

                    else
                    {
                      // it should delete the lines 
                    }

                }
            }
            while (tsr.Peek() != -1);
            tsr.Close();  

Please suggest me how to delete lines and note if textline finds “InsertInto” it should not delete any content from there .

  • 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-25T20:41:57+00:00Added an answer on May 25, 2026 at 8:41 pm

    You read in the file just the same way you were doing. However, if the line doesn’t contain what you are looking for, you simply skip it. In the end, whatever data you are left over with you then write to a new text file.

                private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder newText = new StringBuilder();
            using (StreamReader tsr = new StreamReader(targetFilePath))
            {
                do
                {
                    string textLine = tsr.ReadLine() + "\r\n";
    
                    {
                        if (textLine.StartsWith("INSERT INTO"))
                        {
    
                            newText.Append(textLine + Environment.NewLine);
                        }
    
                    }
                }
                while (tsr.Peek() != -1);
                tsr.Close();
            }
    
            System.IO.TextWriter w = new System.IO.StreamWriter(@"C:\newFile.txt");
            w.Write(newText.ToString());
            w.Flush();
            w.Close();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table and a text file. Once the records in the table
I have Text file that contains data separated with a comma , . How
I have text file with some text information and i need to split this
b'h i will be programmatically importing a text file into a table. i have
I have a fairly simple table requestparams ( requestid varchar(64) NOT NULL, requestString text,
I have database table represented as text file in the following pattern: 0|ALGERIA|0| haggle.
I have text file(test.data), which include(this is just example other files have more values....)
I have a Text File on browser and I want to display textfile data
I have a text file containing data/fields which are separated by exact column no.
I have a text file that I parse each month and insert the data

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.