Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Differences between CompareStr and CompareString

I'm hoping someone can shed some light on this for me: What are the differences, in Delphi 2009, between the CompareStr (defined in SysUtils) and CompareString (from Windows API) functions?

Both let you specify the locale to be used, is the Windows one simply more "complete", due to the available comparison flags? Is one consequently faster than the other?

like image 548
Bourgui Avatar asked Mar 19 '10 00:03

Bourgui


1 Answers

CompareString uses locale information so that things like ae and æ are treated as matches, and sorting is appropriate for the geographical region.

CompareStr('', loInvariantLocale) is just a byte-by-byte comparison of the characters in a string. CompareStr('', loUserLocale) calls CompareString internally, so they're identical, other than the additional flags that CompareString can accept. It's also inlined, so you shouldn't see any difference in speed between it and calling CompareString directly.

like image 141
Zoë Peterson Avatar answered Sep 30 '22 00:09

Zoë Peterson