Remove a special character from a file and save in same file.
I have to read a file, search for a special character 'ç', its ascii equivalent is 0231 (c-cedilla) and replace it with a space. I have tried File class's ReadAllBytes / ReadAllText / ReadAllLines with Encoding.ASCII to read the file, but when it comes to this special character, it reads as '?' whose ascii equivalent is 63. How to do this? Any kind of help will be appreciated.
Thanks in advance
harry
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted May 29, 2009, 2:57 AM EDT
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("sample.txt",true);
string str = sr.ReadToEnd();
sr.Close();
StringBuilder sb = new StringBuilder();
foreach (char c in str)
{
if (c == 'ç')
{
char x = ' ';
sb.Append(x);
}
else
{
sb.Append(c);
}
}
string final = sb.ToString();
StreamWriter sw = new StreamWriter("sample.txt",false,Encoding.UTF8);
sw.Write(final);
sw.Close();
}
Harish Sharma16 reputationPosted Jul 9, 2009, 8:50 AM EDT