Friday, 10 May 2019

Go language: Repeat a string n times


‘strings.Repeat’ function is used to repeat a string given number of times.

Example
msg1 := strings.Repeat("*", 50)

Above statement stores 50 *’s in msg1.

App.go
package main

import (
 "fmt"
 "strings"
)

func main() {
 msg1 := strings.Repeat("*", 50)
 msg2 := strings.Repeat("@", 50)

 fmt.Println(msg1)
 fmt.Println(msg2)
}

Output
**************************************************
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Previous                                                 Next                                                 Home

No comments:

Post a Comment