$STRCMP (compare strings)
$STRCMP compares two character strings.
Syntax
return-value=$STRCMP(character-string-1,character-string-2)
Values
-
return-value
Specifies the name of the variable into which the comparison results are set.
-
If character-string-1 is smaller than character-string-2, 0 is returned to return-value.
-
If character-string-1 is equal to character-string-2, 1 is returned to return-value.
-
If character-string-1 is greater than character-string-2, 2 is returned to return-value.
-
-
character-string-1
Specifies a comparison character string, either as a constant or a variable. A constant must be enclosed in single quotation marks ('').
-
character-string-2
Specifies a character string to compare, either as a constant or a variable. A constant must be enclosed in single quotation marks ('').
Status
The following table lists and describes the possible statuses:
Status |
Description |
---|---|
NORMAL |
Normal end |
NODATA |
— |
ERROR |
— |
Script execution interrupted |
An invalid argument was specified, or an error other than the above occurred. |
Example
The following example compares the characters strings of DATA1 and DATA2, and outputs STRCMP IDENTICAL if the strings are identical, and STRCMP DIFFERENT ($STRCMP-return-value) if they are not identical:
[SET_VALUE] DATA1 = 'Asset Console1' DATA2 = 'Asset Console2' VAL = $STRCMP(DATA1,DATA2) [IF] VAL = 1 [THEN] [SET_VALUE] MSG = 'STRCMP IDENTICAL' $ECHO(MSG) [ELSE] [SET_VALUE] MSG = 'STRCMP DIFFERENT ('+VAL+')' $ECHO(MSG) [IF_END]
- Execution result:
-
STRCMP DIFFERENT (0)