Welcome To Golang By Example

Menu
  • Home
  • Blog
  • Contact Us
  • Support this website
Menu

Create count/repeating copies of a string in Go (Golang)

Posted on March 22, 2020March 22, 2020 by admin

Table of Contents

  • Overview
  • Code:

Overview

strings package of GO provides a Repeat method that can be used to create repeating copies of a given string. It takes input as the number of counts.

Below is the signature of the function. It returns a copy of the string

func Repeat(s string, count int) string

Let’s look at the working code

Code:

package main

import (
    "fmt"
    "strings"
)

func main() {
    res := strings.Repeat("abc", 4)
    fmt.Println(res)
}

Output:

abcabcabcabc
  • go
  • Follow @golangbyexample

    Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2025 Welcome To Golang By Example | Design: Newspaperly WordPress Theme