Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing characters in C# (ascii)
    primarykey
    data
    text
    <p>I got a file with characters like these: à, è, ì, ò, ù - À. What i need to do is replace those characters with normal characters eg: à = a, è = e and so on..... This is my code so far:</p> <pre><code>StreamWriter sw = new StreamWriter(@"C:/JoinerOutput.csv"); string path = @"C:/Joiner.csv"; string line = File.ReadAllText(path); if (line.Contains("à")) { string asAscii = Encoding.ASCII.GetString(Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding(Encoding.ASCII.EncodingName, new EncoderReplacementFallback("a"), new DecoderExceptionFallback()), Encoding.UTF8.GetBytes(line))); Console.WriteLine(asAscii); Console.ReadLine(); sw.WriteLine(asAscii); sw.Flush(); } </code></pre> <p>Basically this searches the file for a specific character and replaces it with another. The problem that i am having is that my if statement doesn't work. How do i go about solving this? </p> <p>This is a sample of the input file:</p> <pre> Dimàkàtso Mokgàlo Màmà Ràtlàdi Koos Nèl Pàsèkà Modisè Jèrèmiàh Morèmi Khèthiwè Buthèlèzi Tiànà Pillày Viviàn Màswàngànyè Thirèshàn Rèddy Wàdè Cornèlius ènos Nètshimbupfè </pre> <p>This is the output if use : line = line.Replace('à', 'a'); :</p> <pre> Ch�rl�n� Kirst�n M�m� R�tl�di Koos N�l P�s�k� Modis� J�r�mi�h Mor�mi Kh�thiw� Buth�l�zi Ti�n� Pill�y Vivi�n M�sw�ng�ny� Thir�sh�n R�ddy W�d� Corn�lius �nos N�tshimbupf� </pre> <p>With my code the symbol will be removed completely</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload