Get the EncodingProvider object in the static CodePagesEncodingProvider.Instance property.
#ANSI TXT FILE ON MAC CODE#
NET Core, do the following:Īdd a reference to the code page assembly to your project.
#ANSI TXT FILE ON MAC WINDOWS#
NET Framework on the Windows desktop but not in. Registering the encoding provider using the RegisterProvider method will also passįollow the CodePagesEncodingProvider line to find, in the official Microsoft document, there is a paragraph in the description of the CodePagesEncodingProvider.Instance property : If there are multiple encoding providers, the Encoding.GetEncoding method will try to retrieve the specified encoding from each provider, starting with the most recently registered provider. After registering the encoding provider, you can retrieve the encodings it supports by calling any Encoding.GetEncoding overload. Using the RegisterProvider method, you can register classes derived from EncodingProvider to make character encodings available on platforms that do not support them. One of the descriptions seems to have a glimmer of hope: What to do then! The Encoding.RegisterProvider method is mentioned in the error message center.
Found a lot of coding, Net Framework and. So I checked the official documentation of the Encoding class. So, mine got a big error message! GB2312 is an unsupported encoding name. String inlines = File.ReadAllLines(infile, Encoding.GetEncoding("GB2312")) (For example, the standard cannot keep up with the needs of actual practice) and the character set will be expanded)Īccording to the description of this article, we can know that the encoding format of the input txt file should be GB2312, so the code for reading the file is changed to Different languages and regional settings in the operating system may use different code pages (the code page is generally not completely equivalent to the character set directly corresponding to it, often due to various reasons The code page is also called "internal code table", which is a table corresponding to the character set of a specific language. Supplement: Enter the black box of the command line under windows, right-click and click Properties to see the current encoding method and code page
(GBK is expanded on the basis of the national standard GB2312 and contains more characters) First of all, ANSI does not refer to a specific code, but a general term for extended coding methods in different regions, independently developed by each country and region ASCII compatibleīut the character encodings that are incompatible with each other are collectively referred to as ANSI encoding by Microsoft
#ANSI TXT FILE ON MAC FULL#
The full name of ANSI (American National Standard Institite) is the American National Standards Institute (a non-profit organization in the United States). The ANSI format I want to read is no longer in this range.īecause I don't know much about character encoding, I searched the Internet and found a very good article on cnblog: Overview of encoding methods ASCII, ANSI, and Unicode. Later, I used the Encoding.GetEncodings() method to obtain all the supported encoding formats, and found that there are only 8 types: UTF8, UTF7, UTF32, Unicode, BigEndianUnicode, ASCII, Default. String inlines = File.ReadAllLines(infile, Encoding.Default) īut what kind of encoding should be added? Tried a few but it didn't work. That is, add a file encoding parameter in the File.ReadAllLines() function. So try to change the encoding of the read file. So I opened the txt file with Notepad and saw that the file encoding displayed in the lower right corner was ANSI. However, I encountered a problem when reading the file: all the Chinese characters in the file became garbled after being read in! What's the problem Outlines.Add(line.Substring(substart, sublength)) Int substart = line.LastIndexOf("/") + 1 String inlines = File.ReadAllLines(infile)