Routines (alphabetical) > Routines: S > STRCMP

# STRCMP

Tip: See also the IDL_String::StartsWith, IDL_String::EndsWith, and IDL_String::Contains methods, which provide similar functionality but with an object-oriented interface.

The STRCMP function performs string comparisons between its two String arguments, returning True (1) for those that match and False (0) for those that do not. Normally, the IDL equality operator (EQ) is used for such comparisons, but STRCMP can optionally perform case-insensitive comparisons and can be limited to compare only the first N characters of the two strings, both of which require extra steps using the EQ operator.

## Examples

Compare two strings in a case-insensitive manner, considering only the first 3 characters:

Result = STRCMP('Moose', 'moo', 3, /FOLD_CASE)
PRINT, Result

IDL prints:

1

## Syntax

Result = STRCMP( String1, String2 [, N], /FOLD_CASE )

## Return Value

If all of the arguments are scalar, the result is scalar. If one of the arguments is an array, the result is an integer with the same structure. If more than one argument is an array, the result has the structure of the smallest array. Each element of the result contains True (1) if the corresponding elements of String1 and String2 are the same, and False (0) otherwise.

## Arguments

### String1, String2

The strings to be compared.

### N

Normally String1 and String2 are compared in their entirety. If N is specified, the comparison is made on at most the first N characters of each string.

## Keywords

### FOLD_CASE

String comparison is normally a case sensitive operation. Set FOLD_CASE to perform case insensitive comparisons instead.

## Version History

5.3 | Introduced

## See Also

String Operations, String Processing, STREGEX, STRJOIN, STRMATCH, STRMID, STRPOS, STRSPLIT, IDL_String