Go string type of language string
, in essence, on the other strings of different types of language:
-
Java's String, C ++, and the std :: string str type Python3 are only fixed-width character sequence
-
Go language character string is a UTF-8 character sequence encoded by widening it with each character represented by one or more bytes
Namely: a language string Go is a arbitrary constant sequence of bytes .
Golang double quotation marks and trans represent a constant string can be used, except that:
-
Double quotes to create a string literal resolvable (support escape, but can not be used to reference multiple lines)
-
Backticks to create native string literal, which may be provided by a string of multiple lines (not support any escape sequence), a string literal native used for writing multiline message, HTML, and regular expressions
The single quotes are used to represent a particular type of Golang: rune
similar to other languages byte
, but not exactly the same, means: code point literal (Unicode code Point) , escaped without any original content.
# Case # procedure, the single quotation marks a, A decimal coding may be encoded incrementally, the error will be replaced by double quotes Package main Import ( " FMT " " Time " ) FUNC worker (ID int, int Chan C) { for { fmt.Printf ( " worker% C% D RUN \ n- " , ID, <- C) } } FUNC chanDemo () { var channels [ 10 ] Chan int for I: = 0; I <10; I ++ { channels [I] = the make (Chan int) Go worker (I, channels [I]) } for I: = 0; I <10; I ++ { channels[i] <- 'a'+i } for i:=0;i<10;i++{ channels[i] <- 'A'+i } time.Sleep(time.Millisecond) } func main() { chanDemo() }