go Repeat()方法

Repeat()语法

func Repeat(s string, count int) string

go源码中对Repeat()方法的介绍:

Repeat returns a new string consisting of count copies of the string s.

It panics if count is negative or if the result of (len(s) * count) overflows.

即go strings标准库模块中的Repeat()方法,可以返回一个以count个s字符串连接起来的新的字符串。


strings.Repeat()实例代码

func main() {
	var newStr string = strings.Repeat("abc", 6)
	fmt.Println(newStr)
}

运行go文件,得到输出:

abcabcabcabcabcabc

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.