Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a very naive and simplistic solution, and assumes that you are working with a very small file, that you don't care about performance, and that the .csv data itself never contains commas. But since you didn't state otherwise, let's assume that getting the job done is the goal, and this will do it:</p> <pre><code>Dim data() As String = System.IO.File.ReadAllLines("C:\Temp\sample.csv") Dim newData = From a In data Where DateTime.Parse(a.Split(","c)(2)) &lt;&gt; #6/10/10# System.IO.File.WriteAllLines("C:\Temp\new.csv", newData) </code></pre> <p>If you need to speed this up or process a larger file, wrap your file reader in an IEnumerable that yields ReadLine() calls instead of reading the whole file into memory at once with ReadAllLines(). If you're .CSV will have quoted identifiers and commas in the data, then you'll need to use a more advance .CSV reader. Microsoft built one in. <a href="http://msdn.microsoft.com/en-us/library/cakac7e6.aspx#Y82" rel="nofollow">See here</a>.</p> <p>-- EDIT --</p> <p>Per request, here's how you could do a file line enumerator in VB. With the class the code changes to <code>From a In New TextFileEnumerator("C:\Temp\sample.csv") Where...</code></p> <pre><code>''' Handy helper class for iterating over lines in a text file. Lets you do something like a ''' Linq-to-files. ''' &lt;/summary&gt; Public Class TextFileEnumerator Implements IEnumerator(Of String), IEnumerable(Of String) Private _filePath As String Private _rdr As StreamReader Private _line As String Private ReadOnly Property StreamReader() As StreamReader Get _rdr = If(_rdr, New StreamReader(_filePath)) Return _rdr End Get End Property Public Sub New(filePath As String) If Not System.IO.File.Exists(filePath) Then Throw New FileNotFoundException(filePath) _filePath = filePath End Sub Public ReadOnly Property Current As String Implements System.Collections.Generic.IEnumerator(Of String).Current Get Return _line End Get End Property Public ReadOnly Property Current1 As Object Implements System.Collections.IEnumerator.Current Get Return _line End Get End Property Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext _line = Me.StreamReader.ReadLine() Return (_line IsNot Nothing) End Function Public Sub Reset() Implements System.Collections.IEnumerator.Reset If _rdr IsNot Nothing Then _rdr.Close() End If _rdr = Nothing End Sub Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of String) Implements System.Collections.Generic.IEnumerable(Of String).GetEnumerator Return Me End Function Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator Return Me End Function #Region "IDisposable Support" Private disposedValue As Boolean ' To detect redundant calls ' IDisposable Protected Overridable Sub Dispose(disposing As Boolean) If Not Me.disposedValue Then If disposing Then If _rdr IsNot Nothing Then _rdr.Close() _rdr.Dispose() _rdr = Nothing End If End If ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. ' TODO: set large fields to null. End If Me.disposedValue = True End Sub ' TODO: override Finalize() only if Dispose(disposing As Boolean) above has code to free unmanaged resources. 'Protected Overrides Sub Finalize() ' ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. ' Dispose(False) ' MyBase.Finalize() 'End Sub ' This code added by Visual Basic to correctly implement the disposable pattern. Public Sub Dispose() Implements IDisposable.Dispose ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload