TODO: Byte of that little thing go
650) this.width=650; "class=" Alignnone size-full wp-image-996 "src=" http://www.todosomeone.com/wp-content/uploads/ 2016/12/12800003df376b8ed9ca-1.jpg "width=" 640 "height=" 530 "style=" border:0px;vertical-align:middle;margin:0px Auto;height:auto; "alt=" 12800003df376b8ed9ca-1.jpg "/>
(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,
650) this.width=650; "class=" Alignnone size-full wp-image-997 "src=" http://www.todosomeone.com/wp-content/uploads/ 2016/12/127c00010479249758e0-1.jpg "width=" 640 "height=" 813 "style=" border:0px;vertical-align:middle;margin:0px Auto;height:auto; "alt=" 127c00010479249758e0-1.jpg "/>
Output:
650) this.width=650; "class=" Alignnone size-full wp-image-998 "src=" http://www.todosomeone.com/wp-content/uploads/ 2016/12/12820000ba444d258a72-1.jpg "width=" 384 "height=" "style=" border:0px;vertical-align:middle;margin:0px Auto;height:auto; "alt=" 12820000ba444d258a72-1.jpg "/>
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
650) this.width=650; "class=" AlignCenter size-full wp-image-845 "src=" http://www.todosomeone.com/wp-content/uploads /2016/11/qrcode_for_gh_6bb1f39ae99c_258-1.jpg "alt=" qrcode_for_gh_6bb1f39ae99c_258-1 "width=" 258 "height=" 258 " style= "border:0px;vertical-align:middle;margin:0px auto;height:auto;text-align:center;"/>
This article is from the computer language driven data blog, so be sure to keep this source http://onetodo.blog.51cto.com/12321875/1879770
TODO: Byte of that little thing go