C # How to Solve the garbled characters when streamreader reads Chinese Text

Source: Internet
Author: User
Write and write a text file ProgramIn the process, there are the following CodeStreamreader sr = new streamreader (filename); garbled characters are displayed when a Chinese text file is opened. The reason is that since Windows 2000 and later operating systems use Unicode by default during file processing, the default file encoding for. NET is also Unicode. Unless otherwise specified, streamreader is encoded as Unicode by default, rather than the ANSI code page of the current system. However, most documents are still stored in ANSI encoding, and Chinese text uses gb2312, which causes Chinese garbled characters. That is to say, you must specify the encoding format when reading the text. But the problem is, system. Text. Encoding inside a pile of encoding format ASCII, UTF-8, etc., which one to choose? In fact, it is very simple to use system. Text. encoding. Default to tell streamreader the encoding of the current operating system. Streamreader reader = new streamreader (filename, system. Text. encoding. Default)
URL: http://greatverve.cnblogs.com/archive/2011/07/08/streamreader-unicode.html
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.