i need access a text file & change individual fields

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Onaylı Üye
Katılım
16 Ocak 2021
Mesajlar
50
Tepki puanı
2
Ödüller
1
Yaş
25
5 HİZMET YILI
I've managed to change individual fields but then end up deleting everything else in the file. I only want to edit one field. Any help would be greatly appreciated. Thankyou
C#:
public static void UpdatePatientData()
        {
            string detail, choice;
     
            Console.WriteLine("Please enter the ID of the customer you would like to Update: ");
            ID = Console.ReadLine();

            string[] Name = File.ReadAllText("user.txt").Split('|'); // each field will represent an index from 1-4

            for (int i = 0; i < Name.Length; i++)
            {
                if (Name[i].Contains(ID))
                {
                    // here is where i would like to edit the name/gender/age etc and write it back to the file

                }
            }
        }
 
Süper Üye
Katılım
7 Ocak 2021
Mesajlar
659
Çözümler
21
Tepki puanı
72
Ödüller
3
5 HİZMET YILI
using c# for such a use-case is a bit overkill.

Excel would be much simpler. you will also most probably find a ready-made vba script that will do what you want with minor tweaking.

Unless you're doing this for educational purposes. then go ahead
 
Onaylı Üye
Katılım
16 Ocak 2021
Mesajlar
50
Tepki puanı
2
Ödüller
1
Yaş
25
5 HİZMET YILI
using c# for such a use-case is a bit overkill.

Excel would be much simpler. you will also most probably find a ready-made vba script that will do what you want with minor tweaking.

Unless you're doing this for educational purposes. then go ahead
Thanks.. yes i needed for educational purposes
 
Onaylı Üye
Katılım
31 Ocak 2021
Mesajlar
56
Çözümler
2
Tepki puanı
7
5 HİZMET YILI
If file is not too big, read it and keep in ram, make your changes in programm and re-wright it
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...