strings.Repeat() 函数按指定的次数重复指定的字符串
实例1:
package main
import "fmt"
import "strings"
func main() {
var str string = "India "
var result string
result = strings.Repeat(str, 4)
fmt.Println("String After repetition:", result)
}
输出:
String After repetition: India India India India
实例2:
package main
import (
"fmt"
"strings"
)
func main(){
s := "hello world hello world"
//将n个字符串s连接成一个新的字符串
ret := strings.Repeat(s,2)
fmt.Println(ret)
}
输出:
hello world hello worldhello world hello world