TODO: Byte of that little thing go
(This article go version go1.7.3 darwin/amd64)
In Golang, the bottom string is made up of a byte array.
Fmt. Println (Len ("DSD Good"))
The length of the output is 6
Fmt. Println (Len (Rune (' Good ')))
The length of the output is 3
Fmt. Println (Len ([]rune ("Good 2s"))
The length of the output is 4
So if you use string to store Unicode, if you have Chinese (Chinese is made up of 3 bytes
), press the subscript is not accessible, because you can only get a byte. If you want to access Chinese, you still need to use the Rune slice, so you can press the subscript access.
UTF-8 (8-bit Unicode Transformation Format) is a variable-length character encoding for Unicode, also known as the Universal Code. Created by Ken Thompson in 1992. It is now standardized to RFC 3629. UTF-8 encodes Unicode characters in 1 to 4 bytes. Use on the Web page to display the Chinese simplified traditional and other languages (such as English, Japanese, Korean) on a unified page.
Why do you want to do UTF-8 transcoding? Very large languages directly support UTF-8, and some languages store strings into memory directly using UTF-8 encoding. UTF-8 is a universal solution that has been maintained for some time. For example, Golang language directly supports UTF-8.
Next, let's see how Golang handles UTF-8 transcoding,
Output:
Why FMT. Println (Strtobyte ("country")) output [11]? By first understanding that the byte to range is 0~256,22283 to 256 the remainder is 11.
In Golang This is how you use UTF-8, do you notice the details of the use?
Wxgzh:ludong86
TODO: Byte of that little thing go