Why does this text not equal the game object's name?

I am trying to set this if statement to true if the text in a textbox is equal to the game objects name.

Debug.Log(nameText.text);

Debug.Log(gameObject.name);

if (nameText.text == gameObject.name)
{
     Debug.Log("True");
}
else
{
     Debug.Log("False");
}

The output is:

NPC

NPC

False

I tested something similar and it worked perfectly.

using UnityEngine;
using UnityEngine.UI;

public class TestText : MonoBehaviour
{
    public Text nameText;

    void Start()
    {
        Debug.Log(nameText.text);
        Debug.Log(gameObject.name);
        Debug.Log(nameText.text == gameObject.name);
        if (nameText.text == gameObject.name) {
            Debug.Log("True");
        }
        else {
            Debug.Log("False");
        }
    }
}

And the Console result:
133051-a1.png
I suggest you double check whether the two texts are equal or not. For instance, there might be a space or change line mark at the end.

If it does not solve your issue, you may paste more code and I will check for you.

Best Regards,