using System;
using System.IO;
namespace insert_text_in_textfile
{
class Program
{
static void Main(string[] args)
{
FileStream fs = new FileStream("d:\\test.txt", FileMode.Open, FileAccess.ReadWrite);
StreamReader sr = new StreamReader(fs);
StreamWriter sw = new StreamWriter(fs);
string s, find = "Programming";
s = sr.ReadToEnd();
int i = s.IndexOf(find);
s = s.Insert(i + find.Length, " PHP,");
fs.Position = 0;
fs.SetLength(s.Length);
sw.Write(s);
sw.Close();
sr.Close();
fs.Close();
}
}
}
/*
Before:
First Line
Programming C#, C
Next line
*/
/*
After:
First Line
Programming PHP, C#, C
Next line
*/