---
tags:
    - "Add"
    - "Append"
    - "Combine"
    - "Merge"
    - "Plus"
    - "Sum"
    - "Text"
---

# Concatenate

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

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Appends the second text at the end of the first one, with an optional separator

## Parameters

| Name | Description |
| :--- | :---------- |
| Text 1 | The text placed at the beginning |
| Text 2 | The text appended at the end |
| Separator | The text placed between both values. Empty by default |

## Code

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

namespace VisualScript.Runtime
{
    [Get]

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

    [Description("Appends the second text at the end of the first one, with an optional separator")]
    [Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgePlus))]

    [Parameter("Text 1", "The text placed at the beginning")]
    [Parameter("Text 2", "The text appended at the end")]
    [Parameter("Separator", "The text placed between both values. Empty by default")]

    [Keywords("Add", "Append", "Combine", "Merge", "Plus", "Sum", "Text")]

    [Serializable]
    public class TypeStringConcatenate : TypeString
    {
        [SerializeField] private GetString m_Text1 = new GetString();
        [SerializeField] private GetString m_Text2 = new GetString();
        [SerializeField] private GetString m_Separator = new GetString(string.Empty);

        public override string GetPreview(GameObject source) => Concatenate(
            this.m_Text1.GetPreview(source),
            this.m_Text2.GetPreview(source),
            this.m_Separator.GetPreview(source)
        );

        public override string Get(Args args) => Concatenate(
            this.m_Text1.Get(args),
            this.m_Text2.Get(args),
            this.m_Separator.Get(args)
        );

        private static string Concatenate(string text1, string text2, string separator)
        {
            return string.Concat(text1 ?? string.Empty, separator ?? string.Empty, text2 ?? string.Empty);
        }

        public override string ToString()
        {
            return $"{this.m_Text1} + {this.m_Text2}";
        }

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

```

