MIAMEX 174: String Compare

Added January 2009

xcall MIAMEX, MX_STRCMP, s1, s2, flags, result

MX_STRCMP compares two strings in various ways.

Parameters

s1, s2  (String)  [in]

are the strings to compare. Only the first 256 characters are considered.

flags  (Num)  [in]

may be set to one or more of the following:

Symbol

Value

Meaning

STRCMPF_LDF

&h01

Use LDF collating sequence

STRCMPF_NAT

&h02

Use "natural" compare (see "natural sort" above)

STRCMPF_FOLD

&h04

Case insensitive comparison

Definition file: ashell.def

 

result (Signed num)  [out]

Value

Meaning

<0

s1 < s2

>0

s1 > s2

0

s1 = s2

 

Comments

With flags=0, you should get nearly the same results as in the standard BASIC string comparison, except that BASIC string comparison ignores trailing blanks, while MX_STRCMP only ignores them if the "natural" flag is set.

The standard BASIC string comparison does not take into account the LDF collating sequence, so for example it will treat accented characters as sorting above the non-accented equivalent.

Unless you modify the LDF accordingly, the standard LDF collating sequences do not change the order of the ASCII characters 1-127, so even with the LDF option, lower case characters are treated as being greater than upper case.

You can check the status of the collating sequences in your LDF file by using DUMP xxxxxx.LDF (the lower collating sequence starts at offset CE in the first block, and the upper collating sequence starts at offset CC in the second block). Or, you can use the updates GTLANG.BAS sample program included in the EXLIB.

History

2009 January, A-Shell 5.1.1136:  Routine added to A-Shell