strCompare (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


strCompare compares two strings and returns a number that specifies which one of the strings is greater than the other or if they are equal. It is possible to test strings without case sensitivity - that is to say that "abc" will be the same as "ABC". If no case-checking is done (see input parameter CheckCase).

 

 

Input:

str1 : STRING

String 1 for the compare function.

 

str2 : STRING

String 2 for the compare function.

 

CheckCase : BOOL Default: FALSE

TRUE if the search should be case-sensitive.

 

Returns: INT(-1,0,1)

-1

if str1 < str2

0

if str1 = str2

1

if str1 > str2

 

Declaration:

FUNCTION strCompare : INT;
VAR_INPUT
  str1, str2 : STRING;
  CheckCase : BOOL := FALSE;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
 compareresult : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  ...
 compareresult := strCompare(str1:="hello", str2:="HeLLo");
  // Compareresult will be 0 because the two strings a equal (because of CheckCase is default FALSE)
  ...
 compareresult := strCompare(str1:="hello", str2:="HeLLo", CheckCase:=TRUE);
  // Compareresult will be 1 because str1 < str2
  ...
 compareresult := strCompare(str1:="ABC", str2:="def");
  // Compareresult will be -1 because str2 > str1, and CheckCase is default equal to FALSE
  ...
END;
 
END_PROGRAM;