Faced the following problem: there is a file in ANSI encoding and I read it line by line, but as far as I understood correctly, in C # this read line is stored in Unicode and in it I observe some hieroglyphs. What I do (on the example of the 1st line of the file):
StreamReader read = new StreamReader(@"D:\(path)"); StreamWriter write = new StreamWriter(@"D:\(path)"); Encoding ANSI = Encoding.GetEncoding(1252); Encoding UTF8 = Encoding.UTF8; byte utf8_bytes,ansi_bytes; utf8_bytes = UTF8.GetBytes(read.ReadLine()); ansi_bytes = Encoding.Convert(UTF8, ANSI, utf8_bytes); string ansi_str = ANSI.GetString(ansi_bytes); write.WriteLine(ansi_str); read.Close(); write.Close();
But for some reason this does not work: the new file still displays many incomprehensible question marks. Thank you in advance.