FString/FText doesn't compare correctly?

FText test = FText().FromString(“ls”);
if (test.ToString().ToLower().Compare(FText().FromString(“ls”).ToString()))
{
OwnerHUD->PlayerOwner->ClientMessage(“true”);
}
else
{
OwnerHUD->PlayerOwner->ClientMessage(“false”);
}

The above code prints false. Why? it seems to me that they should be equal. Am I wrong?

FString::Compare is a 3-way comparison function… it returns <0 if the first string is lexicographically before the second, >0 if it’s lexicographically after and ==0 if they are lexicographically equal. So they are in fact comparing equal, because Compare is returning zero, which is ‘false’.

If you do this, you should get ‘true’:

if (test.ToString().ToLower() == FText().FromString("ls").ToString())

Steve

1 Like

It looks like the FString.Equal function does what I thought FString.Compare did. Makes sense, thanks :slight_smile: