---
tags:
    - "String"
    - "Prefix"
    - "Begins"
    - "Head"
    - "Find"
---

# Starts With

[Strings](index.md) / **Starts With**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Returns True if a text begins with another one

## Parameters

| Name | Description |
| :--- | :---------- |
| Text | The text that is checked |
| Prefix | The text expected at the beginning |
| Ignore Case | Whether upper and lower case characters are considered the same |

## Code

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

namespace VisualScript.Runtime
{
    [Get]

    [Title("Starts With")]
    [Category("Strings/Starts With")]

    [Description("Returns True if a text begins with another one")]
    [Image(typeof(IconString), ColorTheme.Type.Yellow, typeof(BadgeArrowLeft))]

    [Parameter("Text", "The text that is checked")]
    [Parameter("Prefix", "The text expected at the beginning")]
    [Parameter("Ignore Case", "Whether upper and lower case characters are considered the same")]

    [Keywords("String", "Prefix", "Begins", "Head", "Find")]

    [Serializable]
    public class TypeBoolStringStartsWith : TypeBool
    {
        [SerializeField] private GetString m_Text = new GetString();
        [SerializeField] private GetString m_Prefix = new GetString();
        [SerializeField] private GetBool m_IgnoreCase = new GetBool(false);

        public override bool GetPreview(GameObject source) => StartsWith(
            this.m_Text.GetPreview(source),
            this.m_Prefix.GetPreview(source),
            this.m_IgnoreCase.GetPreview(source)
        );

        public override bool Get(Args args) => StartsWith(
            this.m_Text.Get(args),
            this.m_Prefix.Get(args),
            this.m_IgnoreCase.Get(args)
        );

        private static bool StartsWith(string text, string prefix, bool ignoreCase)
        {
            if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(prefix)) return false;

            return text.StartsWith(prefix, ignoreCase
                ? StringComparison.OrdinalIgnoreCase
                : StringComparison.Ordinal);
        }

        public override string ToString()
        {
            return $"{this.m_Text} starts with {this.m_Prefix}";
        }

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

```

