---
tags:
    - "Letter"
    - "Index"
    - "Position"
    - "Char"
    - "Text"
---

# Character At

[Operations](../index.md) / [Extract](index.md) / **Character At**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Returns the single character found at the specified index. Empty if out of range

## Parameters

| Name | Description |
| :--- | :---------- |
| Text | The text to read the character from |
| Index | The zero based index of the character |

## Code

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

namespace VisualScript.Runtime
{
    [Get]

    [Title("Character At")]
    [Category("Operations/Extract/Character At")]

    [Description("Returns the single character found at the specified index. Empty if out of range")]
    [Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeString))]

    [Parameter("Text", "The text to read the character from")]
    [Parameter("Index", "The zero based index of the character")]

    [Keywords("Letter", "Index", "Position", "Char", "Text")]

    [Serializable]
    public class TypeStringCharacterAt : TypeString
    {
        [SerializeField] private GetString m_Text = new GetString();
        [SerializeField] private GetInteger m_Index = new GetInteger(0);

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

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

        private static string CharacterAt(string text, int index)
        {
            if (string.IsNullOrEmpty(text)) return string.Empty;
            if (index < 0 || index >= text.Length) return string.Empty;

            return text[index].ToString();
        }

        public override string ToString()
        {
            return $"{this.m_Text}[{this.m_Index}]";
        }

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

