String Comparison Functions

AMPS includes several types of string comparison operators:

  • Case-Sensitive Exact Matches - The IN, =, BEGINS WITH, ENDS WITH, and INSTR operators do literal matching on the contents of a string. These operators are case-sensitive.

  • Case-Insensitive Exact Matches - AMPS also provides two case-insensitive operators: INSTR_I, a case-insensitive version of INSTR, and a case-insensitive equality operator, STREQUAL_I.

  • Regular Expression Matches - AMPS also provides full regular expression matching using the LIKE operator, described in Regular Expressions.

The = operator tests whether a field exactly matches the literal string provided.

/status = 'available'

/orderId = 'F327AC'

BEGINS WITH and ENDS WITH test whether a field begins or ends with the literal string provided. The operators return TRUE or FALSE.

/Department BEGINS WITH ('Engineering')

/path NOT BEGINS WITH ('/public/dropbox')

/filename ENDS WITH ('txt')

/price NOT ENDS WITH ('99')

AMPS allows you to use set comparisons with BEGINS WITH and ENDS WITH. In this case, the filter matches if the string in the field begins or ends with any of the strings in the set.

/Department BEGINS WITH ('Engineering', 'Research', 'Technical')

/filename ENDS WITH ('gif', 'png', 'jpg')

The INSTR operator allows you to check to see if one string occurs within another string. For this operator, you provide two string values. If the second string occurs within the first string, INSTR returns the position at which the second string starts, or 0 if the second string does not occur within the first string. Notice that the first character of the string is 1 (not 0). For example, the expression below tests whether the string critical occurs within the /eventLevels field.

INSTR(/eventLevels, "critical") != 0

AMPS also provides INSTR_I and STREQUAL_I functions for performing case-insensitive comparisons.

STREQUAL_I(/couponCode, 'QED') == 1

INSTR_I(/symbolList, 'MSFT') != 0

The following table lists the string comparison functions and operators in AMPS:

Function or OperatorParametersDescription

=

The string to be compared

The string to compare

Case-sensitive

Returns true if the string to be compared is identical to the string to compare.

 /state = 'Ohio' 

BEGINS WITH

The string to be compared

A list of strings to compare

Case-sensitive

Returns true if the string to be compared begins with any of the strings in the list.

 /state BEGINS WITH ('North', 'South') 

ENDS WITH

The string to be compared

A list of strings to compare

Case-sensitive

Returns true if the string to be compared ends with any of the strings in the list.

 /state ENDS WITH ('Dakota', 'Carolina') 

INSTR

The string to be compared

The string to compare

Case-sensitive

Returns the position at which the second string starts, or 0 if the second string does not occur within the first string.

This function is not unicode-aware.

 INSTR(/state, 'i') != 0 

INSTR_I

The string to be compared

The string to compare

Case-insensitive

Returns the position at which the second string starts, or 0 if the second string does not occur within the first string.

This function is not unicode-aware.

 INSTR_I(/state, 'i') != 0 

STREQUAL_I

The string to be compared

The string to compare

Case-insensitive

Returns true if, when both strings are transformed to the same case, the string to be compared is identical to the string to compare.

This function is not unicode-aware.

 STREQUAL_I(/state, 'oHIO') != 0 

LENGTH

The string to be counted

Returns the length of the provided string.

 LENGTH(/streetAddress) > 50 

Last updated

Copyright 2013-2024 60East Technologies, Inc.