Coding problems with StreamWriter () in RichTextBox in C #

Source: Internet
Author: User
Tags character set constructor
stream| Code | problem

Problem Description:

WIN2000SP4 Chinese, vs2005 English, oracle9i.

In the program, there is a RichTextBox, to display the SQL statements of the database, use StreamWriter () to write the contents of RichTextBox into a text file, but if the SQL statement contains Chinese, there will be garbled.

Reason for error:

  • Constructor StreamWriter (String), by default, UTF-8 encoding to create the StreamWriter, so there is garbled.

Solution:

  • The constructor StreamWriter (string,encoding) can specify the appropriate encoding.

StreamWriter sw = new StreamWriter (Filename,false, System.Text.Encoding.Default); (Problem solving)

System.Text.Encoding.Default This value is related to the setup of the operating system, which is related to the locale of the control Panel and the language option, similar to the Oracle character set.




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.