Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Remove Range#

Operations / Transform / Remove Range

  • Can Read

  • Cannot Write

Description#

Removes a portion of a text starting at an index and with a certain length

Parameters#

Name Description
Text The text that has a portion removed
From The character index where the removal starts
Length How many characters are removed. Values out of range are clamped

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Remove Range")]
    [Category("Operations/Transform/Remove Range")]

    [Description("Removes a portion of a text starting at an index and with a certain length")]
    [Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeIndex))]

    [Parameter("Text", "The text that has a portion removed")]
    [Parameter("From", "The character index where the removal starts")]
    [Parameter("Length", "How many characters are removed. Values out of range are clamped")]

    [Keywords("Delete", "Cut", "Slice", "Erase", "Text")]

    [Serializable]
    public class TypeStringRemoveRange : TypeString
    {
        [SerializeField] private GetString m_Text = new GetString();
        [SerializeField] private GetInteger m_From = new GetInteger(0);
        [SerializeField] private GetInteger m_Length = new GetInteger(1);

        public override string GetPreview(GameObject source) => RemoveRange(
            this.m_Text.GetPreview(source),
            (int) this.m_From.GetPreview(source),
            (int) this.m_Length.GetPreview(source)
        );

        public override string Get(Args args) => RemoveRange(
            this.m_Text.Get(args),
            this.m_From.GetInt(args),
            this.m_Length.GetInt(args)
        );

        private static string RemoveRange(string text, int from, int length)
        {
            if (string.IsNullOrEmpty(text) || length <= 0) return text ?? string.Empty;

            from = Mathf.Clamp(from, 0, text.Length);
            length = Mathf.Clamp(length, 0, text.Length - from);

            return text.Remove(from, length);
        }

        public override string ToString()
        {
            return $"Remove {this.m_Text} ({this.m_From}, {this.m_Length})";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.