Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:38:43+00:00 2026-05-26T15:38:43+00:00

I have a CSV file with many rows in which I need to update/replace

  • 0

I have a CSV file with many rows in which I need to update/replace column four’s value using VB.NET. There are no headers on the columns so the loop can start on row one.

infile.csv
“value1″,”value2″,”value3″,”value4”

After much googling, there are lots of examples on how to read and write CSV files, but none quite what is needed. I know there are multiple ways to accomplish this task, but a requirement is that it’s done with VB.NET. Any help would be greatly appreciated.


Final code ported from Marco’s C# answer

    Private Sub CSVmod(ByVal strFileName As String, ByVal newFileName As String)

    Dim strLines As String() = File.ReadAllLines(strFileName)
    Dim strList As New List(Of String)
    Dim strReplace As String = "test"

    For Each line In strLines
        Dim strValues As String() = line.Split(",")
        If (strValues.Length = 14) Then
            strValues(3) = strReplace

            strList.Add(String.Join(",", strValues))
        End If

    Next

    File.WriteAllLines(newFileName, strList.ToArray())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:38:44+00:00Added an answer on May 26, 2026 at 3:38 pm

    I’m sorry, but I can write it only in C#.
    I think you won’t find many problems to convert to VB.NET.
    Here is my code:

    private void SubstFile(string filename, string newFileName)
    {
        // Reading all rows of the file
        string[] lines = File.ReadAllLines(filename);
    
        List<string> list = new List<string>();
        foreach (string line in lines)
        {
            // For every row I split it with commas
            string[] values = line.Split(',');
            // Check to have 4 values
            if (values.Length == 4)
            {
                // Substitute fourth value
                values[3] = "new value";
                // Add modified row to list
                list.Add(String.Join(",", values));
            }
        }
        // Save list to new file
        File.WriteAllLines(newFileName, list.ToArray());
    }
    

    VB.NET version:

    Private Sub SubstFile(filename As String, newFileName As String)
        ' Reading all rows of the file
        Dim lines As String() = File.ReadAllLines(filename)
    
        Dim list As List(Of String) = New List(Of String)()
        For Each line As String In lines
            ' For every row I split it with commas
            Dim values As String() = line.Split(","c)
            ' Check to have 4 values
            If values.Length = 4 Then        
                ' Substitute fourth value
                values(3) = "new value"
                ' Add modified row to list
                list.Add(String.Join(",", values))
            End If
        Next
        ' Save list to new file
        File.WriteAllLines(newFileName, list.ToArray())
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a CSV file with php. Many of the rows have a
I'm loading a CSV file containing many thousands of rows into a .NET DataTable
I have a file.csv with 300,000 rows. Many of the rows are the names
I have a CSV file. It has many lines. In each line there are
I have a CSV file that has only 1 column, but has close to
I have a CSV file which has the following format: id,case1,case2,case3 Here is a
I have a CSV file the first row of which contains the variables names
I have a CSV file the first row of which contains the variables names
I have a CSV file with many duplicate entries. How do I import the
My goal here is to have the browser download a csv file using headers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.