0

I have a csv file. I need to open it, delete whole row on basis of a column value, Update few of the column values and save the file as .dat file. I am using VB.net 2010

1

1 Answer 1

1

You can use LINQ to load, remove and update your CSV, for example:

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)

Tested with this csv-file with US-presidents.

Option Strict On | Option Infer On | Option Explicit On

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.