SORU
22 Kasım 2012, PERŞEMBE


Ve c bulunan bir dosya içinde metin Bul ve değiştir nasıl#

Benim kod şimdiye kadar

StreamReader reading = File.OpenText("test.txt");
string str;
while ((str = reading.ReadLine())!=null)
{
      if (str.Contains("some text"))
      {
          StreamWriter write = new StreamWriter("test.txt");
      }
}

Şimdi benim metin dosyası içindeki metni değiştirmek için nasıl hiçbir fikrim yok ancak metin buldum.

CEVAP
22 Kasım 2012, PERŞEMBE


Tüm dosya içeriği okuyun. String.Replace ile bir yedek yapmak. İçeriği tekrar dosyaya yaz.

string text = File.ReadAllText("test.txt");
text = text.Replace("some text", "new value");
File.WriteAllText("test.txt", text);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Christian Atlas

    Christian At

    26 Mart 2009
  • JTechTalk

    JTechTalk

    11 Temmuz 2010
  • Sali Kaceli

    Sali Kaceli

    24 ŞUBAT 2009