delphistring-comparisondelphi-xe7

How to test two strings for ordinal case-insensitive equality using TStringHelper?


I might have overlooked something, but it seems that there is no built-in function like:

var
  B: Boolean;
  S: string;
begin
  S := 'Test';
  B := S.SameText('TEST');
  Assert(B);
end;

.NET has a three parameter version for Equals:

string.Equals(S, "TEST", StringComparison.OrdinalIgnoreCase);

The two versions I can come up with is:

// Ordinal?
string.CompareText(S, 'TEST') = 0
// Culture specific
string.Compare(S, 'TEST', True, TLanguages.UserDefaultLocale)

What puts me off here is that I have to compare to 0, instead of good old SameText:

SameText(S, 'TEST')

Did Embarcadero overlook to provide a SameText on TStringHelper?


Solution

  • Did Embarcadero overlook to provide a SameText on TStringHelper?

    Yes.