MyGUI::UString == and != operators not working as intended?

Locien

09-05-2013 16:56:35

For some reason I can't get MyGUI to compare its strings properly with the == and != operators.

if(mChatInputText->getText(0,1) != "/")
{
mChatTextHistory->addText(mChatInputText->getText(0,1)); //Adds text to the read only box.
mChatTextHistory->addText("\n");
mChatInputText->eraseText(0, mChatInputText->getTextLength()); //Erases the text of the input field.
}


Basically this is a function that adds text to a read only text field from an input field, like a text box of an online game. I can't get it to skip this code in any way. I've also tried to cast it as:
if(mChatInputText->getText(0,1) != (MyGUI::UString)"/")
But it doesn't help.

This is what it looks like:


What am I supposed to do to get string comparison to work? Do I have to cast it to an std::string or convert it to a const char*?

Altren

10-05-2013 15:48:02

Looks like getText also return colour tag even if you never used it thus you was getting "#000000/" string instead of "/". I'm not sure if this is bug or not, may be method just need some additional description.
You can use next code:if(!mChatInputText->getOnlyText().empty() && mChatInputText->getOnlyText()[0] != '/')

Edit: if you also need to pass empty string, then it would be if(mChatInputText->getOnlyText().empty() || mChatInputText->getOnlyText()[0] != '/')

Locien

10-05-2013 19:39:57

Thanks, it worked like a charm. I didn't understand what was wrong since it only displays / when you print it in an edit box.