String Comparing 

www.madshi.net

If you want to test whether 2 strings are identical (but case insensitive), you can either use the well known "SysUtils.CompareText" or you can use the following function, which is *way* faster than misusing "CompareText" for this purpose:

function IsTextEqual (const s1, s2: string) : boolean;

// Examples:
IsTextEqual('test123abc', 'test123'   )  ->  false
IsTextEqual('test123abc', 'Test123ABC')  ->  true

The problem of "SysUtils.CompareText" is, that special characters like umlauts or french characters are not handled correctly. Of course you can use "AnsiCompareText", but that function is quite slow in comparison. My "CompareText" has none of those problems.

My "CompareStr" is basically identical to "SysUtils.CompareStr", but I've left it there nevertheless, because importing "SysUtils" in small programs is generally a bad idea.

function CompareStr  (const s1, s2: string) : integer;
function CompareText (const s1, s2: string) : integer;

Sometimes you want to match 2 strings, of which one may contain wildcard characters. With "Str/TextMatch" you can do such a check easily, and with quite high speed. "StrMatch" checks case sensitively, while "TextMatch" checks case insensitively. "FileMatch" works similar to "TextMatch", but is able to handle the "fileName.ext" logic correctly.

function  StrMatch (str,   mask: string) : boolean;
function TextMatch (str,   mask: string) : boolean;
function FileMatch (file_, mask: string) : boolean;

// Examples:
StrMatch  ('test123abc','test???abc')  ->  true
StrMatch  ('test123abc','test?abc'  )  ->  false
StrMatch  ('test123abc','test*abc'  )  ->  true
StrMatch  ('test123abc','TEST*abc'  )  ->  false
TextMatch ('test123abc','TEST*abc'  )  ->  true
TextMatch ('test123abc','*.*'       )  ->  false
FileMatch ('test123abc','*.*'       )  ->  true

If the capabilities of "Str/TextMatch" are not good enough for you, here are extended versions of them, which additionally support the syntax "[!Length:0,1,2,4..7]". It's a bit difficult to explain this syntax, so please have a look at the examples. I hope they are good enough to show you how it works.

function  StrMatchEx (str, mask: string) : boolean;
function TextMatchEx (str, mask: string) : boolean;

// Examples:
StrMatchEx  ('test123abc','test[3:0..9]abc'      )  ->  true
StrMatchEx  ('test123abc','test[3:a..z,A..Z]abc' )  ->  false
StrMatchEx  ('test123abc','test[!3:a..z,A..Z]abc')  ->  true
StrMatchEx  ('test123abc','test123[3:A,b,C]'     )  ->  false
TextMatchEx ('test123abc','test123[3:A,b,C]'     )  ->  true