# STRING\_COMPARE

**The function STRING\_COMPARE compares two string and outputs a Number indicating their lexicographical order.**

This function takes two [strings](../../variable-data-types/the-text-variable-data-type) as input. It outputs a [Number](../../variable-data-types/the-number-variable-data-type) that indicates the lexicographical order of the input strings. If the first string comes before the second in lexicographical order, output is -1. If the second string comes before the first, output is 1. If the strings are identical, output is 0.

#### Declaration

```javascript
STRING_COMPARE(string1, string2) -> comparison_result
```

#### Parameters

**string1** (required, type: _string_) The first string.

**string2** (required, type: _string_) The second string.

#### Return Values

**comparison\_result** (type: _Number_) The number that indicates the lexicographical order of **string1** and **string2**. -1 indicates that the first string comes before the second, 1 means that the second string comes before the first, and 0 means that the strings are identical.

#### Examples

The following example compares the string "Apples" with the string "Bananas". "A" comes before "B" alphabetically, so STRING\_COMPARE indicates that the first string, "Apples", comes before the second string, "Bananas", in lexicographical order:

```javascript
STRING_COMPARE("Apples", "Bananas") -> -1
```

The following example again compares the string "Apples" with the string "Bananas", but this time "Apples" is listed after "Bananas", so STRING\_COMPARE indicates that the first string, "Bananas", comes after the second string, "Apples", in lexicographical order:

```javascript
STRING_COMPARE("Bananas", "Apples") -> 1
```

The following example compares the string "Apples" with the identical string "Apples", and STRING\_COMPARE indicates that they are, in fact, identical:

```javascript
STRING_COMPARE("Apples", "Apples") -> 0
```

The variant of lexicographical ordering used by STRING\_COMPARE places short strings before longer ones. The following example compares the string "Apples" with the string "Apples and more" and indicates that "Apples" comes first:

```javascript
STRING_COMPARE("Apples", "Apples and more") -> -1
```

Lexicographical ordering is case sensitive; in the variant used by STRING\_COMPARE, lowercase letters come before uppercase. The following example compares the string "Apples" with the string "apples" and indicates that "apples" comes first:

```javascript
STRING_COMPARE("Apples", "apples") -> 1
```

Strings can contain numbers as well as letters. The variant of lexicographical ordering used by STRING\_COMPARE places numbers before letters. The following example compares the string "A" with the string "9" and indicates that "9" comes first:

```javascript
STRING_COMPARE("A", "9") -> 1
```

#### Discussion

"Lexicographical" is derived from the word "lexicon," meaning the set of characters used in a language. The characters in a lexicon have a conventional ordering, such as the letters in the English alphabet. Putting words in alphabetical order is putting them in lexicographical order.

While the letters in the English alphabet have a well-established order, their place in relation to non-letter characters is less standardized. There exist variants of lexicographical ordering that arrange some non-letter characters differently. The variant used by STRING\_COMPARE (and, in fact, all of Airscript) places lowercase letters before capital, symbols and punctuation before numbers, numbers before letters, and empty spaces before occupied spaces (that is, shorter strings before longer strings).
