Please enable JavaScript to view this site.

 

int = StrCompare(sOne, sTwo, bCaseSensitive)

 

This macro function compares two strings, sOne and sTwo, and returns -1 if sOne is "less" than sTwo, 0 if they are both equal, and +1 if sOne is "more" than sTwo.

 

➢By more and less, we mean the position of each string in an alphabetical listing.

 

This function is used to sort strings.

StrCompare('A', 'Z', false);       // returns -1
StrCompare('AAA', 'aaaa', false);  // returns -1
StrCompare('AAAB', 'aaaa', false); // returns +1
StrCompare('A', 'a', false);       // returns  0
StrCompare('Aaaa', 'aaaa', false); // returns  0

The Boolean parameter, bCaseSensitive, determines if the comparison is to take uppercase and lowercase letters into account.

StrCompare('A', 'Z', true);       // returns -1
StrCompare('AAA', 'aaaa', true);  // returns +1  <---
StrCompare('AAAB', 'aaaa', true); // returns +1
StrCompare('A', 'a', true);       // returns +1  <---
StrCompare('Aaaa', 'aaaa', true); // returns +1  <---

Note that the sort order is determined by the regional settings of Windows on your PC; this has an impact for strings which contain letters such as å æ ø.

 

See also: StrContains.

 


Topic 137200, last updated on 18-Apr-2020