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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:44:09+00:00 2026-05-16T23:44:09+00:00

In my program, I read in a file using this statement: string[] allLines =

  • 0

In my program, I read in a file using this statement:

string[] allLines = File.ReadAllLines(dataFile);  

But I want to apply a Regex to the file as a whole (an example file is shown at the bottom) so I can eliminate certain stuff I’m not concerned with in the file. I can’t use ReadAllText as I need to read it line by line for another purpose of the program (removing whitespace from each line).

Regex r = new Regex(@"CREATE TABLE [^\(]+\((.*)\) ON");  

(thanks to chiccodoro for this code)
This is the Regex that I want to apply.

Is there any way to change the array back into one text file? Or any other solution to the problem?
Things that pop into my mind is replacing the ‘stuff’ that I’m not concerned with with string.Empty.

example file

USE [Shelleys Other Database]
CREATE TABLE db.exmpcustomers(
    f_name varchar(100) NULL,
    l_name varchar(100) NULL,
    date_of_birth date NULL,
    house_number int NULL,
    street_name varchar(100) NULL
) ON [PRIMARY]
  • 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-16T23:44:09+00:00Added an answer on May 16, 2026 at 11:44 pm

    It’s going to be really hard to use regexen to deal with multi-line data a line at a time. So rather than muck about with that, I’m going to suggest that you first read it as one big string, do your multi-line regex business, and then you can split it into an array of strings using String.Split (split on newlines). The reason you want to do it in this order is so that any further operations on your file data will include the changes already made by the regex. If you join the strings, then do the regex, you will either have to split that string again, or lose the changes you’ve made to it while you operate on the original array.

    Remember to use this for your regex matching, so that it will match across newlines:

    Regex r = new Regex(@"CREATE TABLE [^(]+((.*)) ON", RegexOptions.SingleLine);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to read file /proc/'pid'/status, using c program. The code is as follows,
I have a c program that is trying to read in a file. Using
This is a clojure program to read integers from a file and count the
i am trying to read an excel file using java. while compiling the program
I make program to read xml file by using traditional JavaScript. <script type=text/javascript> var
i have to write a program in C to read a file containing several
I am trying to read a binary file from a program that writes a
So I have the following read and write file program for an Array. How
I am reading a text file line by line in C++. I'm using this
I am developing a simple Java program to create an Excel file using (Apache

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.