Get the App
SLTechnology News&Howtos  ›  Servers  › 

Highlights of Windows Chinese coding display problems

Shulou Source: shulou.com Published: 2022-06-02 15:43:01 09月15日 Update

1) solution of Chinese garbled code in console

The root of the problem

The reason for the garbled Chinese display is the coding format set by the console. If the encoding format set by the console is GBK and the storage content of the database is UTF-8, of course it cannot be displayed normally.

Solution

1) start CMD to view the current character set encoding, and use the instruction chcp

Active code page:65001: UTF-8 coding

Activity Code Page: 936: GBK Encoding

Note: many users want to be able to enter Chinese under the console. They must use the instruction chcp 936 and switch to GBK encoding format before they can enter Chinese normally.

2) currently view the UTF-8-encoded database file and use the instruction chcp 65001 to switch to the UTF-8-encoded character set

3) enter the directory of the sqlite.exe program, start sqlite.exe, and display the contents of the UTF-8 database normally

4) if the database content is GBK encoded, you can use chcp 936.

2) VS debugging: invalid characters in the string

Scene

The message sent by the network is utf-8-encoded Json data, which is saved in Chinese. When parsing with Jsoncpp, debug the obtained variable in one step. When getting the variable containing Chinese, check the std::string string variable and prompt. The character in the string is invalid.

Analysis

A new feature added in the higher version of VS, if the string contains non-printed characters, or utf8 encoding, the debugger automatically displays: the characters in the string are invalid. It has been misled here that Jsoncpp cannot correctly parse the format of utf-8 encoding. In fact, Jsoncpp has already parsed the content, but it cannot display Chinese in this case. It must be GBK encoding.

Course

Std::string strName = root ["name"] .asString (); / / Chinese characters in name: wind and rain are on the way.

Navigate to strName at this time, indicating that the characters in the string are invalid

Solve

Add strName to monitor. After the name strName, add S8, and it will display normally.

Examples

Name value

StrName,s8 is on its way through wind and rain.

Tags: Character coding Chinese string data UTF-8 content database time format control variable instruction console garbled name character set solution wind and rain Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Redmi MariaDB Microsoft Apple