<div class="meta" robots="noindex">

</div>

Method

# StrComp

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `String.Compare<string.compare>` as a replacement.

</div>

## Description

Makes a binary (case-sensitive) or text (lexicographic) comparison of the two `strings</api/data_types/string>` passed and returns the result.

## Usage

*result* = **StrComp**(*string1*, *string2*, *mode*)

| Part    | Type                               | Description                                                      |
|---------|------------------------------------|------------------------------------------------------------------|
| result  | `Integer</api/data_types/integer>` | Returns the result of the comparison of *string1* and *string2*. |
| string1 | `String</api/data_types/string>`   | The first string for comparison.                                 |
| string2 | `String</api/data_types/string>`   | The second string for comparison.                                |
| mode    | `Integer</api/data_types/integer>` | The comparison mode, Binary or Text.                             |

## Notes

The text comparison is lexicographic, not case-insensitive. This means that case will be taken into account if the strings are the same (other than case).

When using Mode 0 (binary), <span class="title-ref">StrComp</span> always compares the bytes of the strings as they are, doing no encoding conversions. It's possible that two strings might look the same on screen but be reported as different in <span class="title-ref">StrComp</span> Mode 0 if they are in different encodings (and, therefore, contain different bytes).

<div class="note">

<div class="title">

Note

</div>

See the `ComparisonOptions</api/language/comparisonoptions>` enumeration for values you can use with <span class="title-ref">StrComp</span>.

</div>

## Sample code

The following code returns -1 because the two strings are the same in every way except in case:

``` xojo
StrComp("Spam", "spam", REALbasic.StrCompLexical)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following code returns -1 because in a byte comparison of the two strings, string2 is greater than string1. The ASCII value of "S" is less than the ASCII value of "s".

``` xojo
StrComp("Spammer", "spam", REALbasic.StrCompCaseSensitive)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code compares two values lexicographically:

``` xojo
Var s1 As String = "happy"
Var s2 As String = "Hello"

Var result As Integer
result = StrComp(s1, s2, REALbasic.StrCompLexical)
' result = 1
```

## Compatibility

All project types on all supported operating systems.

## See also

`String<string.indexof>` function; `\></api/language/operators/comparison/greater_than>`, `\>=</api/language/operators/comparison/greater_than_or_equal>`, `\<</api/language/operators/comparison/less_than>`, `\<=</api/language/operators/comparison/less_than_or_equal>`, `=</api/language/operators/comparison/equals_operator>`, `<></api/language/operators/comparison/not_equal>` operators.
