UTF8 turn into GB2312 garbled solution _xml Example

Source: Internet
Author: User
Recently done a small project, encountered such problems, recorded, is a summary.
This project is divided into two parts, one is news data acquisition, one is the audit of information acquisition, the final generation of XML files.

After data is edited by the user, export an Access file and import the file into the information audit system. The field type that stores news information in an Access library is the ntext type, and the corresponding varchar (max) type of field is in the Audit system library, and after the import, some white space characters are found to appear as a question mark (?). In fact, after the test, this is not a blank (space) character, and a special character, what to do? After several tests, it was found that the varchar (max) type was changed to the nvarchar (max) type so that the imported data would not have such a problem.

But later in the test process, it will also find that after the import of the acquisition information changes (through the. NET program editing function), the database of this information and the garbled problem, after the study found in the INSERT statement this will not appear such a problem, such as insert into table name (news) VALUES ( N ' "+ Updated value +" "), why add n? Go to Baidu for a moment to understand.

To this end, the heart finally get comfort, but the problem behind let people fall into the depression ...
Audit information to generate XML-type files, and XML to use GB2312 encoding, because the collection of news sites, there are many sites using the UTF8 code, so in the process of conversion and garbled (or that "blank" special characters engaged in), how to do? Online introduction of the UTF8 into the GB2312 can be, but actually found, or can not solve the problem, this morning in order to solve this problem, finally there is no way, is depressed, suddenly think of the debugging through vs to see what this special character is what thing, Finally, the content is converted into a character array by reading the field value of the database. ToCharArray (); One of the look, found that led to garbled this character is ' attention to the blank in quotation marks, this is not a space, but a special character in the GB2312 can not be recognized at this time, suddenly thought, can the value of this character directly with a space replacement? Immediately action, sure enough, solved the garbled problem. Really beg to be depressed, this one hair thing wasted a half a day of time.

Note that you have to debug this value (because this is really the special character that causes garbled characters), when debugging in even the form to paste.
Copy Code code as follows:

Content = content. Replace ("", "");

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.