المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Edit text file using C#



C# Programming
05-30-2013, 04:03 PM
Dear All,

I am editing some lines in aP text file using c#, while editing the (') is replacing with another new charachter, i dont want this can any one help with code

StringBuilder newFile = new StringBuilder();
string temp = "";
string[] AllLines = File.ReadAllLines(FileName);
strStart = &quot;<&quot;;
foreach (string strLine in AllLines)
{
if (strLine.Contains(&quot;CUsers&quot;) || strLine.Contains(&quot;_ags&quot;))
{
fIndex = strLine.IndexOf(strStart);
sIndex = strLine.LastIndexOf(&quot;_ags&quot;);
temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
newFile.Append(temp + &quot;\r\n&quot;);
continue;
}
newFile.Append(strLine + &quot;\r\n&quot;);
}
File.WriteAllText(FileName, newFile.ToString());


Thanks in advance,
Srikanth

srikanth