title: Writing data to a text file in a format
body: <p>Im trying to get some particular content from a site and place it in text file. i have used a listbox for loop of urls i want to process and another to see output of data. now i want all data in text file each item seperated by "~" sysmbol.</p>
  
  <p>Exmaple Link i used in my.txt file: <a href="http://www.maxpreps.com/high-schools/abbeville-yellowjackets-(abbeville,al)/basketball/previous_seasons.htm" rel="nofollow">http://www.maxpreps.com/high-schools/abbeville-yellowjackets-(abbeville,al)/basketball/previous_seasons.htm</a></p>
  
  <p>Data expected in text file:<br>
  Abbeville High School Basketball Stats ~ Team: Varsity 11-12 ~ Colors: Maroon, Gray, White ....</p>
  
  <pre><code>Imports System.IO.StreamReader
  Imports System.Text.RegularExpressions
  Imports System.IO
  
  
  Public Class Form1
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim abc As String = My.Computer.FileSystem.ReadAllText("C:\Documents and Settings\Santosh\Desktop\my.txt")
          Dim pqr As String() = abc.Split(vbNewLine)
          ListBox2.Items.AddRange(pqr)
  
      End Sub
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
          For Each item In ListBox2.Items
              Dim request As System.Net.HttpWebRequest = System.Net.WebRequest.Create(item)
              Dim response As System.Net.HttpWebResponse = request.GetResponse
  
              Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
              Dim rsssource As String = sr.ReadToEnd
              Dim r As New System.Text.RegularExpressions.Regex("&lt;h1 id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_Header""&gt;.*&lt;/h1&gt;")
              Dim r1 As New System.Text.RegularExpressions.Regex("&lt;span id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_Mascot""&gt;.*&lt;/span&gt;")
              Dim r3 As New System.Text.RegularExpressions.Regex("&lt;span id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_Colors""&gt;.*&lt;/span&gt;")
              Dim r4 As New System.Text.RegularExpressions.Regex("&lt;span id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_GenderType""&gt;.*&lt;/span&gt;")
              Dim r5 As New System.Text.RegularExpressions.Regex("&lt;span id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_AthleteDirectorGenericControl""&gt;.*&lt;/span&gt;")
              Dim r6 As New System.Text.RegularExpressions.Regex("&lt;address&gt;.*&lt;/address&gt;")
              Dim r7 As New System.Text.RegularExpressions.Regex("&lt;span id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_Phone""&gt;.*&lt;/span&gt;")
              Dim r8 As New System.Text.RegularExpressions.Regex("&lt;span id=""ctl00_NavigationWithContentOverRelated_ContentOverRelated_Header_Fax""&gt;.*&lt;/span&gt;")
  
              Dim matches As MatchCollection = r.Matches(rsssource)
              Dim matches1 As MatchCollection = r1.Matches(rsssource)
              Dim matches3 As MatchCollection = r3.Matches(rsssource)
              Dim matches4 As MatchCollection = r4.Matches(rsssource)
              Dim matches5 As MatchCollection = r5.Matches(rsssource)
              Dim matches6 As MatchCollection = r6.Matches(rsssource)
              Dim matches7 As MatchCollection = r7.Matches(rsssource)
              Dim matches8 As MatchCollection = r8.Matches(rsssource)
  
  
              For Each itemcode As Match In matches
                  Dim W As New IO.StreamWriter("C:\" &amp; FileName.Text &amp; ".txt")
                  W.Write(itemcode.Value.Split("""").GetValue(2))
                  W.Close()
  
                  'ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(2))
              Next
              For Each itemcode As Match In matches1
                  ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(2))
              Next
          Next item
  
      End Sub
  End Class
  </code></pre>