This is a creation in Article, where the information may have evolved or changed.
The processing of strings inside the go language is not the same as PHP and Java, first declaring the string and modifying the string
[PHP]
Package Main
Import "FMT"
var name string//declaration of a string
var emptyname string = ""//Declare an empty string
Func Main () {
Declare multiple strings and assign values
A, B, V: = "Hello", "word", "Widuu"
Fmt. Println (A, B, v)
To convert the contents of a string, first convert the type of a to []byte
c: = []byte (a)
Assign value
C[0] = ' n '
In converting to a string type, we actually found that our a did not change
But a new change in the string
D: = string (c)
Fmt. Println (d)
String prototype output
M: = ' Hello '
Word '
Fmt. Println (M)
}
[/php]
How to declare an array
[PHP]
Package Main
Import "FMT"
var arr [2]int//Declare an array
Func Main () {
ARR[0] = 1//array assignment
Fmt. Println (arr)
Arrtest: = [3]int{1, 2, 3}//array another way of declaring
Fmt. Println (Arrtest)
A: = [...] Int{1, 2}//[...] Automatically recognize the length of an array
Fmt. Println (a)
Fmt. Println (Len (a))//Length of output array
}
[/php]
Below is the declaration and use of slice in fact, this is a dynamic array
[PHP]
Package Main
Import "FMT"
Func Main () {
D: = []int{1, 2, 3}//Declare a slice this is a dynamic array with no length
Fmt. Println (d)
var q, W []int
Q = d[0:1]//Can be determined to get the top length
W = D[1:3]
D = Append (d, 2)//add element to it
Fmt. Println (d)
Fmt. PRINTLN (q, W)
}
[/php]
Without permission, you may not reprint any article of this website: Micro network emoji language inside the string and array