FaTaLL
FaTaLL

Reputation: 511

Unity TextMeshPro text and string are not the same

basically i'm trying to compare two strings like this;

    public void OnJoinRoom(TextMeshProUGUI roomName)
    {
        Debug.Log("|"+roomName.text+"|");

        string normalString = "123";

        if (roomName.text == normalString)
        {
            Debug.Log("SAME TEXT");
        }
        else
        {
            Debug.Log("NOT SAME TEXT");
        }
        PhotonModel.JoinReservedRoom(roomName.text);
    }

OnJoinRoom fires when a user clicks to my "Join" button and it gets room name from an textmeshpro input field. In summary, i try to create room and other user types the room name and joins. When I try to create room with name "123" and join with the "normalString", it joins the room. But when i get the value from roomName and try to join, it fails. I'm sure i type "123" to the input field. Here is the Console Log.

Example

I could not find any solutions online. I could really use a help here :)

EDIT:

Console Log with roomName length.

enter image description here

Upvotes: 3

Views: 3361

Answers (1)

Ruzihm
Ruzihm

Reputation: 20249

Make sure that roomName refers to the TMP_InputField component (or its equivalent), and not the TMP_Text child component (or its equivalent), which may contain formatting characters.

Upvotes: 3

Related Questions