golang 字符串切片追加字符如何用顿号隔开
要将字符串切片中的字符用顿号隔开,可以使用strings.Join函数将切片中的元素连接起来,并指定用逗号作为分隔符。
例如:
package main
import (
"fmt"
"strings"
)
func main() {
s := []string{"hello", "world", "golang"}
result := strings.Join(s, "、")
fmt.Println(result)
}
输出结果为:
hello、world、golang
原文地址: https://www.cveoy.top/t/topic/iqig 著作权归作者所有。请勿转载和采集!