---
title: "strCompare"
canonical: "https://help.vicon.com/space/ShogunPost121/1253736489/strCompare"
format: markdown
---
# Description

Compares two strings alphabetically.

If the first string is "before" the second string, a value less than 0 is returned. If the second string is "before" the first string, a value greater than 0 is returned. If the two strings are equal, 0 is returned.

By default, the string comparison is case-sensitive (e.g. `A` is less than `a`). It compares ASCII character values, with capital letters (A-Z) being before lower case letters (a-z). This can be overridden with the `-noCase` flag.

This command is useful for sorting lists of strings. If you just want to determine if two strings are identical, use the equality operator ``==`` on the two strings.

## Functional area

String

# Command syntax

## Syntax

> Macro (scroll-tablelayout)

|  |
| --- |
| `strCompare "string1" "string2" [-noCase]` |

### Arguments

| Name | Type | Required | Comments |
| --- | --- | --- | --- |
| `string1` | string | yes | First string to be compared. |
| `string2` | string | yes | Second string to be compared. |

### Flags

> Macro (scroll-tablelayout)

| Name | Flag arguments | Argument type | Exclusive to | Comments |
| --- | --- | --- | --- | --- |
| `noCase` | 0 | — | — | Specifies that the search be case insensitive. The default is case sensitive. |

## Return value

integer

See *Description* section for explanation of the return value.

## Examples

```plaintext
// Demonstrate string comparison.
string $str1 = "Bob";
string $str2 = "Stan";
string $str3 = "bob";
int $val;
 
// Compare the first two strings.
$val = `strCompare $str1 $str2`;
print $val; 
// Should be less than 0
 
// Compare the second and third strings.
$val = `strCompare $str2 $str3`;
print $val; 
// Should be less than 0
 
// Compare the first and the third.
$val = `strCompare $str1 $str3`;print $val; 
// Should be less than 0
 
// Do a case insensitive search of the first and third
$val = `strCompare $str1 $str3 -noCase`;
print $val; 
// Should be 0
```

> Macro (scroll-pagebreak)

# Additional information

## Related commands

- [strFind](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737935)
- [strLeft](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737036)
- [strLength](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253738093)
- [strMid](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737094)
- [strReplace](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736842)
- [strReverseFind](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737016)
- [strRight](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253736764)
- [strTok](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253739563)
- [strTokArray](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253739862)