title: How to replace a row in a file using vb.net
body: <p>I have a csv file which have data like this:</p>
  
  <pre><code>Date,val1,val2,val3,val4,val5,val6,.......val47,val48
  18/07/2011,0,0,0,10.98,0,0,0,10.98,10.98,0,0,0,0,0....,0,0
  </code></pre>
  
  <p>Now i need to compare the date value of existing row with new row's date value. If equal then need to replace the exisiting row with new row. If not append the existing row. I tried in follwing way. If dates are not equal, the new row is getting added but if dates are equal could not able to replace the existing row. Any suggestions please?????</p>
  
  <pre><code>Imports System.IO
  Public Class Form1
      Private _fileName As String = "C:\Desktop\demo.csv"
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  
          Dim reader As New StreamReader(_fileName)
          Dim line As String = reader.ReadLine
          Dim _newLine As String = "18/07/2011,0,0,0,0,0,0,0,10.98,10.98,0,0,0,0,10.98,0,0,0,10.98"
          While line &lt;&gt; ""
  
              line = reader.ReadLine
  
              If line &lt;&gt; "" Then
                  Dim values() As String = line.Split(",")
  
                  If values(0) = "18/07/2011" Then
  
                      _fileName.Replace(line, _newLine)
  
                  End If
  
              End If
  
          End While
          reader.Close()
      End Sub
  End Class
  </code></pre>