How can I check if text content is " "?

How can I check if text content is space with “if” statment?

if (text == " ");

…among several million other ways of doing it. Might want to use String.Contains if there’s other formatting (such as a line break and so on). Strings contain sequence characters as well, which aren’t always visible.

1 Like

Still showing error thought…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class Sub : MonoBehaviour
{
    public GameObject DisText;
  
    void Update()
    {
        if (DisText = " ")
        {
          
        }
    }
}

A GameObject is not a text string but a different class and you can look up what it contains for example the .name property.

If you wanted only text to manipulate, then define it as:

public string DisText;

Which can then be accessed how you expect, for strings.

But if you mean TextMeshPro then you should say so, as that will be an object itself, and contain it’s own .text property.

1 Like

You’re missing another equal sign, when you compare equality you have to do if (DisText.text == " ") (2 times the = character).

1 Like

if (Text.contains(“Text”))
{
Do …
}

Epic Solution . Try it . If your game object name is GameObject01.
Then No problem . Type Just GameObject
if (Text.contains(“GameObject”))
{
Do …
}
Done .