Topic: DMD0164

Help File Version: 2.10.0.636

STRCMP - String Compare


The String Compare (STRCMP) instruction will compare the contents of one String to the contents of a second String or to a String LiteralClosed Zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal data (such as 0xAA).. The instruction determines if two Strings are Equal, Less Than or Greater Than by comparing the byte values of the characters in the respective Strings. The byte value of a String or a string literal is the decimal values assigned to each character. The byte values for each character can be seen in the ASCII Character Table.

 

The instruction compares the byte values for the characters in order until one of the following happens:

 

  • the byte values don't match, this means the string with the smaller byte value is 'less than' the string with the larger byte value.

     

  • the end of one string is reached but the other has remaining characters, this means the shorter string is 'less than' the longer string and the longer string is 'greater than' the shorter string.

     

  • the end of both strings is reached at the same time, meaning the strings are equal.

 

 


Parameters:

Note: Use the F9 key or click the 'three dot box' at the right edge of the parameter field to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.

 

First String - this can be any User-defined or System-defined String.

 


Case Sensitive
 

  • Yes, upper / lower case are different - select this option if the comparison needs to distinguish between upper case and lower case versions of the same characters, that is, "A" is NOT the same as "a".
     

  • No, upper / lower case are equal - select this option if the comparison does not need to distinguish between upper case and lower case versions of the same characters, that is, "A" is the same as "a".

 


Set If Equal - if this option is selected the First String and the Second String must be equal to set the designated BIT location ON. This can be any writable bit location.

 

Set If Less Than - if this option is selected the First String must be less than the Second String to set the designated BIT location ON. This can be any writable bit location.

 

Set If Greater Than - if this option is selected the First String must be greater than the Second String to set the designated BIT location ON. This can be any writable bit location.

 


Second String or Text - this can be any User-defined or System-defined String or a String LiteralClosed Zero or more characters enclosed in double quotes, as in "hello", and may include both simple escape sequences (such as \t for the tab character) and hexadecimal data (such as 0xAA)..

 


Input Leg selects which of the following power-flow conditions will cause this instruction to run:

 

  • Edge Triggered means the instruction will run to completion each time the input ladder logic transitions from OFF to ON.
     
  • Power flow enabled means the instruction will run repeatedly as long as the input ladder logic remains ON.

 


Status Display:

 

The Status display of the String Compare instruction will only display as many of the characters of the First String and Second String or Text as will fit within the borders of the instruction, typically this is about 50 characters.

 


See Also:

STR2REAL - Convert String to Real

 

STR2INT - Convert String to Integer

 

STRCASE - Convert String to UPPER / lower Case

 

STRCLEAR - Clear Strings

 

STRCMP - String Compare

 

STRCOPY - Copy String

 

STRCOPYR - Copy a Range of Strings

 

STRDELETE - Delete Substring

 

STRFIND - Find within String

 

STRINSERT - Insert Substring

 

STRPRINT - Print to String

 

STRSUB - Get Substring

 

STRTRIM - Trim Whitespace

 

STRTRUNC - Truncate String

 

 


Related Topics:

String Functions Overview

 

String Scripting Language Reference

 


Rung Example: