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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lorebass
    New Member
    • Sep 2013
    • 2

    #1

    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.

    Code:
    if (txtFile.Text != "")
                {
                    curFile = txtFile.Text;
                    StreamReader objReader = new StreamReader(curFile);
                    string sLine = "";
                    ArrayList arrText = new ArrayList();
                    while (sLine != null)
                    {
                        sLine = objReader.ReadLine();
                        //if line is not null
                        if (sLine != null)
                        {
                            //if line does not start with //* comments
                            if (!sLine.Contains("//*"))
                            {
                                while (member.Equals(separateJob(sLine)))
                                {
                                    if (sLine.Contains("//") || sLine.Contains("MEMBER NAME"))
                                    {
                                        sLine = ("\n") + sLine;
                                    }
                                    arrText.Add(sLine);
                                }
                            }
                            //separateJob(sLine);
                        }
                        //MessageBox.Show(sLine, "Select File", MessageBoxButtons.OK);
                    }
                    objReader.Close();
                    
    
                    foreach (string sOutput in arrText)
                    {
                        output += sOutput;  //puts on one line
                    }
                    //Output to file
                    System.IO.File.WriteAllText(@"D:\OutputTest.txt", output); //writes out in one line
                    MessageBox.Show(curFile, "Select File", MessageBoxButtons.OK);
                }

    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.
    Last edited by Lorebass; Oct 4 '13, 04:32 PM. Reason: clarify
Working...