In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
You are allowed to repeat a string of for a specific number of times with the help of the Repeat() Function. This method returns a new string which contains a repeated string and it is defined under the strings package. So, you have to import strings package in your program for accessing Repeat function.
func Repeat(str string, count int) string
Here, str represents the string that you want to repeat and the count value represents how many times you want to repeat str string.
Result 1: Welcome to GeeksforGeeks !..Welcome to GeeksforGeeks !..Welcome to GeeksforGeeks !..Welcome to GeeksforGeeks !..
Result 2: This is the tutorial of GoLanguage..Language..
Note: This method will panics if the value of the count is negative or the result of (len(str) * count) overflows.
panic: strings: negative Repeat count
goroutine 1 [running]:
strings.Repeat(0x104b22, 0xa, 0xfffffffe, 0x0, 0x450000, 0x70)
- Counting number of repeating words in a Golang String
- How to count specific characters present in the slice in Golang?
- How to Print Specific date-time in Golang?
- Program to find the Length of the longest substring without repeating characters in Golang
- How to compare times in Golang?
- How to Count the Number of Repeated Characters in a Golang String?
- string.Contains Function in Golang with Examples
- Converting a string variable into Boolean, Integer or Float type in Golang
- Golang Program that uses String Switch
- How to Trim a String in Golang?
- How to convert a string in uppercase in Golang?
- How to convert a string in lower case in Golang?
- Check if the given characters is present in Golang String
- How to Replace Characters in Golang String?
- How to Split a String in Golang?
- How to find the index value of specified string in Golang?
- How to find the last index value of specified string in Golang?
- Check if the String starts with specified prefix in Golang
- Check if the String ends with specified suffix in Golang
- How to check String for equality under Unicode case folding in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.