Results 1 to 3 of 3

Thread: Update Csv file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2020
    Posts
    19

    Update Csv file

    Hi all Iím trying to update a single value in a csv file I wish to change the value of one column from a 1 to 2

    I can find the correct row using

    Code:
     dim lines() as string = io.file.readalllines("csv.txt")
    for x as integer = 0 to lines.getupperbound(0)
        if lines(x).contains(Id) then
            lines(x) = lines(x).replace(Id , "Value4")
        end if
    next
     
    io.file.writealllines("csv.txt", lines)
    But this updates the actual Id I need to step through to the 17th column and change that entry

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,495

    Re: Update Csv file

    Try this...

    Code:
    dim lines() as string = io.file.readalllines("csv.txt")
    for x as integer = 0 to lines.getupperbound(0)
        if lines(x).contains(Id) then
            Dim fields() as string = lines(x).Split(","c)
            fields(17) = "Value4"
            lines(x) = String.Join(",", fields)
            Exit For
        end if
    next
     
    io.file.writealllines("csv.txt", lines)
    Although, the 17th column will be fields(16)...
    Last edited by .paul.; Sep 24th, 2020 at 06:02 PM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2020
    Posts
    19

    Re: Update Csv file

    Worked like a charm
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width