Jens Mühlenhoff
Jens Mühlenhoff

Reputation: 14873

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?

Upvotes: 2

Views: 2991

Answers (2)

Deepak Dhyani
Deepak Dhyani

Reputation: 101

AnsiCompareText - Compares strings based on the current locale without case sensitivity.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613262

Did Embarcadero overlook to provide a SameText on TStringHelper?

Yes.

Upvotes: 4

Related Questions