title: vb.net: How do i split a delimited file out into separate files depending on the flag i set in the code
body: <p>I've got a pipe delimited file that has multiple different flat lines of data.</p>
  
  <p>I want to split out depending on the first field in the data so that i end up with two data files (one with the data i have selected and the other with the remaining data)</p>
  
  <p>e.g</p>
  
  <p><strong>FLAG|random data|random data|random data|random data|random data|random data|
  FLAG1|random data|random data|random data|random data|random data|random data|
  FLAG2|random data|random data|random data|random data|random data|random data|
  FLAG1|random data|random data|random data|random data|random data|random data|</strong></p>
  
  <p>So all the data with FLAG1 would be in one file and then the rest (FLAG2) would be saved off in a separate file.</p>
  
  <p>So far i have this:</p>
  
  <pre><code>Imports System
  Imports System.IO
  
  Public Class Form1
  
      Dim c As Integer
  
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  
          Dim Tr As IO.TextReader = System.IO.File.OpenText("C:\Users\gmck\Desktop\TIG DATA\test_1")
          For c As Integer = 0 To 1500
  
          Next
  
          If c = 0 Then
              Dim MyFileLine As String = Split(Tr.ReadToEnd(), vbCrLf)(c) &amp; vbCrLf
              Tr.Close()
  
              Dim TW As System.IO.TextWriter
              'Create a Text file and load it into the TextWriter 
              TW = System.IO.File.CreateText("C:\Users\gmck\Desktop\TIG DATA\test_NEW")
              TW.WriteLine(MyFileLine)
              'Flush the text to the file 
              TW.Flush()
              'Close the File 
              TW.Close()
          End If
      End Sub
  End Class
  </code></pre>
  
  <p>which pulls out the first record and puts it into a new file.  I can't think how to get it to pull out all the records for a specific flag.</p>
  
  <p>cheers for any help.</p>
  
  <p>Gaz </p>