![]() ![]() The source of this comes from the fact that the Windows code page 1252 was originally based on an ANSI draft-which became International Organization for Standardization (ISO) Standard 8859-1. “The term “ANSI” as used to signify Windows code pages is a historical reference, but is nowadays a misnomer that continues to persist in the Windows community. Interestingly, this doesn’t mean that I’ve saved the file as ANSI – this is a misnomer. But as I mentioned earlier, I know I saved this file with the encoding type ANSI selected from the dropdown list in Notepad. ![]() It turns out detecting the file’s encoding type is quite a difficult thing to do in. NET?īig thanks to Erich Brunner for pointing out a new bit of information to me about the default encoding type – I’ve updated this post to reflect his helpful steer. Can you detect the file’s encoding type with. NET Framework console application is that my StreamReader is assuming that my file is encoded one way when it’s actually encoded in another way, and it doesn’t know what to do with some characters, so it uses a question mark as a default. It’s pretty obvious that the question marks relate to the non-ASCII characters, and each name on my list have either an accent or a grave, or an umlaut/diaeresis. What’s gone wrong? The StreamReader object and original text file need to have compatible encoding types I expected to see my team’s names written to the console – but instead all those names now have question marks scattered throughout them, as shown in the image below. WriteLine( "The file could not be read:") īut when I run the code, there’s a problem. Read the stream to a string, and write the string to the console. So I’ve written a spike of code to use a StreamReader – I’ve more or less copied directly from the link above – and it looks like this: using System Ĭonst string myTeamNamesFile = using ( var streamReader = new StreamReader(myTeamNamesFile)) NET Framework StreamReader – there’s a simple and clear example on the site describing how to do this. I’m going to read names from this text file using a. I saved the file with the default ANSI encoding. I created the text file on Windows 10 machine and used Notepad. The file is pretty simple – it’s called MyTeamNames.txt and it contains the following names: ASCIStringEncoding didn't work.I’ve got a list of my team members in a text file which I need to parse and process in. lowest common denominator)? I believe that used to be the purpose initWithContentsOfFile, which unfortunately is now deprecated.
0 Comments
Leave a Reply. |