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
Harish SharmaPosted Jul 9, 2009, 12:50 PM
Kirtan PatelPosted May 29, 2009, 6:57 AM
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();
}