[To] characters, bytes, and encoding
From: http://www.regexlab.com/zh/encoding.htm
Level: Intermediate
Abstract: This article describes the development process of character and encoding and the correct understanding of related concepts. Examples
Auto: http://www.regexlab.com/zh/encoding.htm
Abstract: This article describes the development process of character and encoding and the correct understanding of related concepts. Examples illustrate how to implement encoding in some practical
The coding problem of Python has never been solved, and finally it is clear from this blog post today.Original address: http://nedbatchelder.com/text/unipain.htmlAddress:
Picture because the file is relatively large, commonly used pictures such as reading the database or file to increase the system load. The use of caching methods can increase
/*** Description: Get the length of the string in bytes;* @ Versions 0.2;* @ Return returns the length of the string in bytes (for example, "12 to 12", the length of the string is 6 );*/String. Prototype. getlength = function (){VaR text = This.
The content of this section:
1. Foreword
2. Related Concepts
Default encoding in 3.Python
Support for strings in 4.python2 and Python3
5. Character encoding Conversion
First, the preface
The character encoding in Python is a commonplace topic,
The content of this section:
Objective
Related concepts
Default encoding in Python
Support for strings in Python2 and Python3
Character encoding Conversion
First, preface
The character encoding in Python is a
String and character encoding in Python, python string EncodingContent of this section: 1. Preface
Character encoding in Python is a common topic, and many articles have been written in this field. Some people are also cloud, and some are well
Let's talk about the strings and character encoding in Python (recommended) and python strings.
Content of this section:
1. Preface
2. Related Concepts
3. default encoding in Python
4. Support for strings in Python2 and Python3
5. character encoding
Character encoding in Python is a common topic, and many articles have been written in this field. Some people are also cloud, and some are well written. Recently, I saw a video from a well-known training institution talking about this issue again,
Original address: Click hereThe content of this section:
Objective
Related concepts
Default encoding in Python
Support for strings in Python2 and Python3
Character encoding Conversion
First, prefaceThe character
When the protocol is resolved. Always encounter a variety of data conversion problems, from binary to Decimal, from byte string to integer, etc.Not much nonsense on. Directly on the sampleBinary conversions between integers:
10-in-turn
Using system;Using system. text;Using system. IO;Namespace charandstring{Class class1{Static void main (string [] ARGs){// The content of string is a unicode string:String STR = "Chinese 123 ";// The length is 5 because it is 5 characters.Console.
Chinese QuestionsHow to write a Chinese program:
Use Chinese to declare the encoding in the first line #encoding =utf-8
The file is saved in utf-8 encoded format , the Chinese string in the file needs U, for example: U ' Chinese '
>>> "Hello". Encode ("hex")' 68656c6c6f '
The corresponding can also
>>> ' 68656c6c6f ' decode ("hex")' Hello '
I checked the manuals, and these codec are available.
Codec
Aliases
Operand type
Purpose
>>> "Hello". Encode ("hex")
' 68656c6c6f '
The corresponding can also
>>> ' 68656c6c6f '. Decode ("hex")' Hello '
Check the manuals, and these codec are available.
Codec
Aliases
Operand type
Purpose
Base64_codec
During network programming, you often need to print the received data in hexadecimal format for easy viewing. Today we found that there is such a simple method in Python.
>>> "Hello". encode ("hex ")'68656c6c6f'
You can also
>>> '68656c6c6f'.
This problem often occurs in our programs. Testing in WINXP is normal, and this problem occurs on the server (Linux operating system.1. Because the mail subject of the program I wrote is written in the configuration file (. properties), and then use
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.