Mega Code Archive

 
Categories / Delphi / OOP
 

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