2011-08-25 56 views

回答

1

您可以使用LINQ來加載,刪除和更新您的CSV,例如:

Const separator = ","c 
Dim csvPath = "C:\Temp\USPresident.csv" 
Dim datPath = "C:\Temp\USPresident.dat" 
Dim rows = (From line In IO.File.ReadAllLines(csvPath) 
       Select line.Split(separator)).ToList 
' get all lines with specific value ' 
Dim presidentRows = (From cols In rows 
       Where cols.Contains("William Howard Taft")).ToList 
' remove these lines with Except' 
Dim rowsWithoutPresident = rows.Except(presidentRows).ToList 
' update some values ' 
For Each row In rowsWithoutPresident 
    row(3) = "test-value" 
Next 
Dim newLines = (From cols In rowsWithoutPresident 
       Select String.Join(separator, cols)).ToArray 
IO.File.WriteAllLines(datPath, newLines) 

測試與this csv-file with US-presidents

Option Strict On | Option Infer在|上Option Explicit

相關問題