❔ changing values in .csv file with file i/o commands

Ccyn1/18/2023
hello, i'm trying to replace a certain column in a csv file with file i/o commands but i can't quite find out how to
Ccyn1/18/2023
Here's an example of the .csv file
Image
Ccyn1/18/2023
...
...
string[] doctors = File.ReadAllLines("Doctor.csv");
    for (int i = 1; i < doctors.Length; i++)
      {
       string[] doctors2 = doctors[i].Split(',');
       if (doctorID == doctors2[0])
          { 
            //Not sure what to do here to replace values
          }

       }
TTimtier1/18/2023
You'd need to open a FileStream on this file to change the contents. Something like a StreamWriter ( or one of its implementations) would then allow you to write in it
TTimtier1/18/2023
Though keep in mind that might become a bit messy considering you'll need to keep the same order of all entries to not mess with data integrity.

Creating an entirely new file and removing/archiving the old one might be easier and safer unless needed
Ccyn1/18/2023
Would that be a better option? (the creating a new file one)
Ccyn1/18/2023
also is there a way to directly replace a file with another file if i do it this way?
TTimtier1/18/2023
Directly, maybe, not sure since im not behind a PC to google :p

But basically:
1. Create new file.
2. Delete (or rename) old file
3. Rename new file to old name.
4. Delete old file if you havent yet.
Ccyn1/18/2023
ohh okay
TTimtier1/18/2023
Id think its better as you can ensure the file is only replaced once your edited file is done, though it depends on your situation
Ccyn1/18/2023
i'll try that, thank you so much <3
TTimtier1/18/2023
Np, good luck 😄
AAccord1/19/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.