How to read and write files in UTF-8 format in win32

1, write data Initially, three bytes are written before writing data. BYTE btHead[] = {<!– –> 0xEF,0xBB,0xBF }; ::WriteFile(hFile, btHead, 3, & amp;dwWrite, 0); ::WriteFile(hFile, str, lstrlen(str)*sizeof(TCHAR), & amp;dwWrite, 0); The file style after writing is: The format is UTF-8, but there is a BOM behind it, and the Chinese characters are also garbled. Finally, […]

Solving UnicodeDecodeError: utf-8 codec cant decode byte 0xc2 in position 0: invalid continuation byt

Table of Contents Solving UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xc2 in position 0: invalid continuation byte error message reason solution Example 1: Read web page content and process it Example 2: Read text file and process it Solving UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xc2 in position 0: invalid continuation byte When processing text […]

Solving SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared

Table of Contents Solving SyntaxError: Non-UTF-8 code starting with \xc0 in file but no encoding declared wrong reason Solution 1. Declare file encoding 2. Convert encoding 3. Remove non-UTF-8 characters 4. Use Unicode escaping Practical application scenarios What is UTF-8 encoding? Characteristics of UTF-8 encoding Application of UTF-8 encoding Solve SyntaxError: Non-UTF-8 code starting with […]

Solving UnicodeDecodeError: utf-8 codec cant decode byte 0xd3 in position 238: invalid continuation b

Table of Contents Solving UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd3 in position 238: invalid continuation byte Method 1: Specify the correct encoding Method 2: Ignore error characters Method 3: Use other encodings to try decoding Method 4: Convert file encoding in conclusion Solving UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd3 in position 238: invalid […]

Solving UnicodeDecodeError: utf-8 codec cant decode byte 0xce in position 130: invalid continuation byt

Table of Contents Solving UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xce in position 130: invalid continuation byte wrong reason Solution 1. Specify the correct encoding method 2. Use error handling 3. Specify file encoding method Solve UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xce in position 130: invalid continuation byte In Python programming, we often encounter […]

The relationship between various encoding formats (GB2312, GBK, GB18030, unicode, utf-8)

Common encoding formats for Chinese characters To display characters on the screen. The following steps are required: Make fonts corresponding to all characters. For example, what does the capital letter A look like. This appearance is the final graphic displayed on the screen, which is the character A we see. To encode all characters. For […]

Download/export problem (uniform return): No converter for xxx with preset Content-Type application/octet-stream; charset=UTF-8

1. Preface The download interface returns download data normally. After the file stream is closed, the response returns success and the console reports an error all content: Probably means there is no converter. Contains the default content type “application/octet-stream;charset=UTF-8” org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class com.cn.common.AjaxResult] with preset Content-Type ‘application/octet-stream;charset=UTF-8’ at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:319) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:194) at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78) […]

scp tab completion error: F-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)

1. Problem description During a certain Linux operation, the function scp command was used, and the following directory could not be completed using Tab. The error was reported: -bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory Related links: character map file `UTF-8’ not found 2. Cause handling 1) As shown […]

A pot of coding knowledge (ASCII, ISO-8859-1 (Latin1), GB2312, GBK, GB18030, BIG5, UTF-8, UTF-16, UTF-32, Bom, garbled code)

Coding knowledge stewed in a pot Coding history Era Encoding Length Description Problem Machine Code Era 01 Binary 8bit Generally, 1 represents high level and 0 represents low level People cannot understand it The Age of Enlightenment ASCII Single Byte American Standard Information Interchange Code, the most common today A single-byte encoding system, the first […]

CentOS 8 reports an error when executing the yum command: Failed to set locale, defaulting to C.UTF-8

Today, Docker created a new CentOS image. When running a container based on this image and executing the yum command, I encountered the following error: [root@GC Administrator]# yum install -y yum-utils Failed to set locale, defaulting to C.UTF-8 CentOS Linux 8 – AppStream 41 B/s | 38 B 00:00 Error: Failed to download metadata for […]