Item Rule String Functions

All string functions are case-sensitive. To perform a case-insensitive comparison use the == comparison operator.

String Comparison Functions

compare

Syntax:

compare(string1, string2)

Returns 0 when string1 is exactly equal to string2. Returns -1 if string1 is lexicographically less than string2. Returns +1 if string1 is lexicographically greater than string2

contains

Syntax:

contains(look_for_string, look_in_string)

Returns TRUE when look_for_string is found in look_in_string. Returns FALSE otherwise.

Example:

The following example returns TRUE if the item description is "computer accessory product".

If Expression: contains("accessory", [item].[main].[description])

endsWith

Syntax:

endsWith(look_for_string, look_in_string)

Returns TRUE when look_in_string ends with look_for_string. Returns FALSE otherwise.

match

Syntax:

match(regexp_pattern, look_in_string)

Returns TRUE when regexp_pattern matches look_in_string. Returns FALSE otherwise..

This function uses regular expression pattern matching in its search. For reference on regular expressions, see the Javadoc reference for java.util.regex.Pattern ( http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html).

Example:

The following example returns TRUE if the description includes "electronic" or "electric".

match("ele*c", [item].[main].[description])

startsWith

Syntax:

startsWith(look_for_string, look_in_string)

Returns TRUE when look_in_string starts with look_for_string. Returns FALSE otherwise.

Example:

The following example returns TRUE if the item description is "Notebook".

startsWith("Note", [item].[main].[description])

Other String Functions

+ (plus sign)

Syntax:

expression1 + expression2

Concatenates two expressions and returns the resulting string. Note that this also returns a valid string if the expressions are of other data types.

indexOf

Syntax:

(look_for_string, look_in_string)

Returns position of look_for_string in look_in_string. String position starts at 0. Returns -1 if look_for_string isn't found. The search is case-sensitive. Returns null if either expression is null.

length

Syntax:

length(expression)

Returns the length of the string expression. Returns null if expression is null.

lowercase

Syntax:

lowercase(expression)

Returns the lowercase equivalent of the string expression. Returns null if expression is null.

replace

Syntax:

replace(look_for_string, replacement_string, look_in_string)

This method returns look_in_string after replacing each substring in look_in_string that matches look_for_string with the replacement_string.

Example:

The following example returns a string in which all instances of Red in the value of an item's description have been replaced with Blue, without altering the value of Item.Main.[Item Description] itself:

replace("Red", "Blue", Item.Main.[Item Description])

You can also use regular expressions for identifying the substring to be replaced.

The following example returns the string in which all the digits with have been replaced with n in an item's Long Description attribute value:

replace("\\d", "n", [Item].[Main].[Long Description])

If the value of Long Description is Sentinel 15V 6A 90W AC Power Adapter, then the example returns Sentinel nnV nA nnW AC Power Adapter

substring

Syntax:

substring(string, start)
substring(string, start, end)

Returns a substring of the string stringstarting at start and ending before end. If end is omitted, then returns remainder of string. String position starts at 0. If start is less than 0 then start at the beginning of the string. If startis greater than length of string then return up to the end of the string. Returns null if any of the arguments is null.

Example:

You can use rules to validate that the Packaging Indicator digit for a GTIN is appropriate for the Pack Type of the item. GTINs can be assigned at multiple levels of a packaging hierarchy. Consider a scenario in which your GTIN numbering rule declares that, if the pack type of the Item is "EA", then the fourth digit of the GTIN should be 8. You can use the following rule expressions in a validation rule to perform this kind of validation.

If Expression: [Item].[Main].[Pack Type] == "EA"
Validation Condition: subString([GTIN].[GTIN Main].[GTIN], 4, 4) == "8"

trim

Syntax:

trim(expression)

Removes all leading and trailing (but not middle) white space characters from a expression. Returns null if expression is null.

uppercase

Syntax:

uppercase(expression)

Returns the uppercase equivalent of the string expression. Returns null if expression is null.