---
tags:
    - "Duplicate"
    - "Multiply"
    - "Loop"
    - "Times"
    - "Text"
---

# Repeat

[Operations](../index.md) / [Composing](index.md) / **Repeat**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Repeats a text a certain amount of times

## Parameters

| Name | Description |
| :--- | :---------- |
| Text | The text that is repeated |
| Times | How many times the text is repeated. Zero returns an empty text |

## Code

```cs
using System;
using System.Text;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Repeat")]
    [Category("Operations/Composing/Repeat")]

    [Description("Repeats a text a certain amount of times")]
    [Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeLoop))]

    [Parameter("Text", "The text that is repeated")]
    [Parameter("Times", "How many times the text is repeated. Zero returns an empty text")]

    [Keywords("Duplicate", "Multiply", "Loop", "Times", "Text")]

    [Serializable]
    public class TypeStringRepeat : TypeString
    {
        [SerializeField] private GetString m_Text = new GetString();
        [SerializeField] private GetInteger m_Times = new GetInteger(2);

        [NonSerialized] private readonly StringBuilder m_Builder = new StringBuilder();

        public override string Get(Args args)
        {
            string text = this.m_Text.Get(args);
            int times = this.m_Times.GetInt(args);

            if (string.IsNullOrEmpty(text) || times <= 0) return string.Empty;

            this.m_Builder.Clear();
            for (int i = 0; i < times; ++i)
            {
                this.m_Builder.Append(text);
            }

            return this.m_Builder.ToString();
        }

        public override string ToString()
        {
            return $"{this.m_Text} x{this.m_Times}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}

```

