---
tags:
    - "Right"
    - "End"
    - "Tail"
    - "Take"
    - "Text"
---

# Last Characters

[Operations](../index.md) / [Extract](index.md) / **Last Characters**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Extracts the rightmost characters of a text

## Parameters

| Name | Description |
| :--- | :---------- |
| Text | The text to extract the characters from |
| Amount | How many characters are taken from the end |

## Code

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

namespace VisualScript.Runtime
{
    [Get]

    [Title("Last Characters")]
    [Category("Operations/Extract/Last Characters")]

    [Description("Extracts the rightmost characters of a text")]
    [Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeArrowRight))]

    [Parameter("Text", "The text to extract the characters from")]
    [Parameter("Amount", "How many characters are taken from the end")]

    [Keywords("Right", "End", "Tail", "Take", "Text")]

    [Serializable]
    public class TypeStringLastCharacters : TypeString
    {
        [SerializeField] private GetString m_Text = new GetString();
        [SerializeField] private GetInteger m_Amount = new GetInteger(1);

        public override string GetPreview(GameObject source) => Last(
            this.m_Text.GetPreview(source),
            (int) this.m_Amount.GetPreview(source)
        );

        public override string Get(Args args) => Last(
            this.m_Text.Get(args),
            this.m_Amount.GetInt(args)
        );

        private static string Last(string text, int amount)
        {
            if (string.IsNullOrEmpty(text) || amount <= 0) return string.Empty;

            amount = Mathf.Min(amount, text.Length);
            return text.Substring(text.Length - amount, amount);
        }

        public override string ToString()
        {
            return $"Last {this.m_Amount} of {this.m_Text}";
        }

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

```

