DelphiFAQ Home Search:
General :: Programming :: Delphi :: Strings
Algorithms for string handling problems, implemented in Delphi but useful for any procedural language.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

CompareString() versus AnsiCompareString()

Question:

What is the difference between CompareString() and AnsiCompareString()?


Stefan Hoffmeister explains:

Some languages have characters outside of the ASCII character set; these two strings will compare differently depending on whether you use CompareString or AnsiCompareString:

CompareString()
'das'
'dau'
'da'

'' is a German character, and with AnsiCompareString, the correct lexical order returned would be different:

AnsiCompareString()
'das'
'da'
'dau'
AnsiCompareString observes the lexical order of your current locale - while CompareString only looks at the bits and bytes of the data. If you want to compare 'text', then do use AnsiCompareString. If you want to compare ASCII-only text (or just bytes), then use CompareString.

Generated 20:01:24 on Feb 17, 2018