In the Go language, string is a string. Its essence is a [[]byte], so they can be converted to each other. The length of the byte array is the length of the string. Once the value of a string is determined, it cannot be modified.
The environment of this article: Windows 10 system, Go 1.11.2 version, this article is applicable to all brands of computers.
(Learning video sharing:Programming video)
The essence of Go language String is a []byte, so they can be converted to each other. The length of the byte array is The length of the string.
Result:
a=H b=e str=Mello,World
Once the value of the string is specified, it cannot be modified. If you want to modify it, you can first replace the string with slice.
//当试图去修改str时候 str[0] = 'M'
The following error message will appear:
## Result:a=H b=e str=Mello,World
strLen=12 str2ByteSlice=12 str2RuneSlice=8
str2RuneSlice[0]=H str2RuneSlice[1]=e str2RuneSlice[2]=l str2RuneSlice[3]=l str2RuneSlice[4]=o str2RuneSlice[5]=, str2RuneSlice[6]=世 str2RuneSlice[7]=界
The above is the detailed content of What does string mean in go language?. For more information, please follow other related articles on the PHP Chinese website!