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

  • CMTelly

    CMTelly

    2 Mayıs 2007
  • Keith Anthe

    Keith Anthe

    26 NİSAN 2011
  • Miles Fisher

    Miles Fisher

    8 NİSAN 2009