要将字符串切片中的字符用顿号隔开,可以使用strings.Join函数将切片中的元素连接起来,并指定用逗号作为分隔符。

例如:

package main

import (
	"fmt"
	"strings"
)

func main() {
	s := []string{"hello", "world", "golang"}
	result := strings.Join(s, "、")
	fmt.Println(result)
}

输出结果为:

hello、world、golang
golang 字符串切片追加字符如何用顿号隔开

原文地址: https://www.cveoy.top/t/topic/iqig 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录