golang rune a few bytes

(*-*)浩
Release: 2019-12-17 10:51:50
Original
2771 people have browsed it

golang rune a few bytes

rune is used to distinguish character values ​​​​and integer values ​​​​                                                                                                                                                                                                                                            Represents a UTF-8 character. When you need to process Chinese, Japanese or other compound characters, you need to use the rune type. The rune type is equivalent to the int32 type. byte is equivalent to int8, which is one byte in length, commonly used to process ascii characters

rune is equivalent to int32, which is 4 bytes in length, and is commonly used to process unicode or utf- 8 characters

##Example:

package main

import (
    "fmt"
)


func main() {
    str := "你好 world"
    fmt.Printf("len(str):%d\n", len(str)) //返回len(str):12
}
Copy after login
The return value is 12 because Chinese characters occupy 2 bytes under unicode and utf-8 encoding It occupies 3 bytes, and golang's default encoding is exactly utf-8.

The above is the detailed content of golang rune a few bytes. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!