Home>Article>Backend Development> How to convert array to string in go language
The method of converting an array into a string in Go language: first traverse all the elements in the array; then append them to string, such as [for _, i := range arr { result = i}].
The operating environment of this article: windows10 system, Go 1.11.2, thinkpad t480 computer.
1. Convert an element in the array directly into a string
arr := make([]string, 0) arr[0] = "sfsdfsdf" string := arr[0] //直接将该数组的一个元素,赋值给字符串 fmt.Printf("====>:%s\n", string)
2. Convert all the data in the array into a string
func arrayToString(arr []string) string { var result string for _, i := range arr { //遍历数组中所有元素追加成string result += i } return result }
Related recommendations:golang tutorial
The above is the detailed content of How to convert array to string in go language. For more information, please follow other related articles on the PHP Chinese website!