473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to separate specific blocks in a text file that have the same name into one file.

I am reading through a text file and want to break down specific blocks of text out of that text file and place it into a new text file.

in my file:

MEMBER NAME J20ASDF
//-----text-----
MEMBER NAME J15QWER
//-----text-----
MEMBER NAME J15QWER
//*Comments
//-----text-----
MEMBER NAME J15QWER
//-----text-----
MEMBER NAME K23JGKD
//-----text-----

I want to take the bolded files out and put them into the same separate file.

Expand|Select|Wrap|Line Numbers
  1. if (txtFile.Text != "")
  2.             {
  3.                 curFile = txtFile.Text;
  4.                 StreamReader objReader = new StreamReader(curFile);
  5.                 string sLine = "";
  6.                 ArrayList arrText = new ArrayList();
  7.                 while (sLine != null)
  8.                 {
  9.                     sLine = objReader.ReadLine();
  10.                     //if line is not null
  11.                     if (sLine != null)
  12.                     {
  13.                         //if line does not start with //* comments
  14.                         if (!sLine.Contains("//*"))
  15.                         {
  16.                             while (member.Equals(separateJob(sLine)))
  17.                             {
  18.                                 if (sLine.Contains("//") || sLine.Contains("MEMBER NAME"))
  19.                                 {
  20.                                     sLine = ("\n") + sLine;
  21.                                 }
  22.                                 arrText.Add(sLine);
  23.                             }
  24.                         }
  25.                         //separateJob(sLine);
  26.                     }
  27.                     //MessageBox.Show(sLine, "Select File", MessageBoxButtons.OK);
  28.                 }
  29.                 objReader.Close();
  30.  
  31.  
  32.                 foreach (string sOutput in arrText)
  33.                 {
  34.                     output += sOutput;  //puts on one line
  35.                 }
  36.                 //Output to file
  37.                 System.IO.File.WriteAllText(@"D:\OutputTest.txt", output); //writes out in one line
  38.                 MessageBox.Show(curFile, "Select File", MessageBoxButtons.OK);
  39.             }
  40.  

I have never really asked a question here before so if im missing anything i'd be glad to post that as well. Mostly here I am lost on the logic. I want to be able to make a separate text file for every member.
Oct 4 '13 #1
0 1128

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rowland Banks | last post by:
Hi, I've got two fields in seperate SQL tables (a and b), both called trackNum. b.trackNum is a foriegn key into a.trackNum. I've got a form with a few bound controls on it (textboxes...
5
by: sdhyok | last post by:
Here is my situation. To add more functionalities to a standard library(datetime) in python, I am implementing my own code called vp.datetime (directory structure, vp/datetime.py). To make it...
0
by: Joe | last post by:
How can I rename a folder that has the same name, but with different character casing? When I do either of the following, I get an error saying "Source and destination path must be different.": ...
17
by: Arnold | last post by:
Is using fseek and ftell a reliable method of getting the file size on a binary file? I thought I remember reading somewhere it wasn't... If not what would be the "right" and portable method to...
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
3
by: Mttc | last post by:
Have a way to have two version of EXE file with same name in one directory
1
by: sandhyabhavani | last post by:
This article is used to zip a file or directory using vb.net. The classes and method to zip a file is availale in java.io, java.util, java.util.zip class library.To import these you have to add a...
1
by: jerger | last post by:
I have not made a program or page from start yet. I have made modifications to our signoff asp pages like changing the questions, texts, shortening field lengths etc... I also have copied the files...
2
by: sidhx | last post by:
how can i let image overwriting when uploading? and if uploading an image say "logo.jpg" and if a file already existing say "logo.png" then, how can i replace the file logo.png to logo.jpg(which has...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.