Remove characters from string from start to finish

Here is an example script that removes letters one by one from the end to start:

    IEnumerator RemoveLetters()
    {
        _CreditsTextBox.alignment = TextAlignmentOptions.MidlineRight;
        char FirstLetter = '';

        // Remove the letters one by one
        while (NewText.Length > 0)
        {
            NewText = NewText.Substring(1); // Remove the first letter of the text
            _CreditsTextBox.text = NewText;

            if (!string.IsNullOrEmpty(NewText))
                FirstLetter = NewText[0];


            yield return new WaitForSeconds(Delay); // Wait for the specified delay
        }
}

this causes some problems with character positions,
There is a different way to print / remove letters with TextMeshPro’s maxVisibleCharacters.

However when removing letters this way, I can only remove it from the end to the start. I want from start to the end.

so when I have a text “Hello”

it will remove H, than e, than l, l, and finish with o.

Thanks :wink:

Fixed it using firstVisibleCharacter.

To anyone who sees this in the future, Here is my code:

IEnumerator RemoveCredits()
    {
        for (int i = 0; i < _CreditsTextBox.text.Length; i++) // Go over all text
        {
            _CreditsTextBox.alignment = TextAlignmentOptions.MidlineRight; // Start removing from left to right so the text should have white spaces instead.

            _CreditsTextBox.firstVisibleCharacter = i;  

            float currentDelay = delay; // So it goes smoothly on spaces
            if (char.IsWhiteSpace(_CreditsTextBox.text*))*

{
currentDelay = 0;
}

yield return new WaitForSeconds(currentDelay); // Wait for the specified delay
}

_CreditsTextBox.text = “”;
}
Enjoy! And have a Great Day! :slight_smile: