How To

Using Text Functions in Business Rules

Text functions allow you to disect, combine, and format text using business rules. Supported functions are listed below.

 

Prerequisites


You should be familiar with the following topics:

 

Text Functions Supported for Business Rules


View the table below for Text Functions supported for Business Rules.

Function Description Example Output
ADDTOCURRENTDATE Adds a value to the current date and returns the new date in the specified format. See GETCURRENDATE for possible date formats and date parts. Interval is just the number of days, months, years, etc. to add to the date. Use negative intervals to get dates in the past. The default templates for Google Shopping use this for feed expiration date.ADDTOCURRENTDATE("yyy-MM-dd","d",30)Returns 2007-05-25(May 25) if the current date is April 25, 2007.

CONCATENATE

Joins up to 8 text strings into one string.  There is no space or other delimiter inserted between the input strings.

CONCATENATE("Space","man")

"Spaceman"

CONCATENATE($ITEMBRAND, " ", $COLOR, " ", $SIZE)

Join together several attributes to form a title.

CONTAINS

Whether search text occurs in a string. The search is case sensitive.

CONTAINS("cookies","ook")true

DEDUP

Given a delimited list of items and the delimiter, returns a delimited list of the unique items.

DEDUP("Red,Blue,Red,Green")

"Blue,Green,Red"

GETCURRENCYCODE Returns the three character currency code abbreviation for the specified locale. Certain providers require this value to be passed in the feed. Normally the default provider templates will take care of this.GETCURRENCYCODE("en-GB")GBP
GETCURRENTDATE Returns the current date in the specified format. The full list of available formatting options is the same as that provided by Microsoft.Net. You can use their documentation on date formats. The basic options are shown below, combine them to get the desired effect. The patterns are case sensitive - "m" returns the minute not the month.GETCURRENTDATE(MMddyyyy)

03212009

GETDAYSBETWEEN

Returns the number of days between the two dates specified in the rule. If both dates are the same, the result is zero.

GETDAYSBETWEEN("05/25/2015", "06/25/2015", "MM/dd/yyyy")

31

GETDAYSSINCE

Returns the number of days between the current date and the date specified in the rule.

GETDAYSSINCE("01/01/2015","MM/dd/yyyy")

If current date is 01/16/2015, this will return 15.

GETPART

Gets the nth part of a text string, where the parts are separated by some character(s). Counts backwards from the end if a negative number is passed.

GETPART("Clothing --> Pants --> Velvet Bellbottoms","-->",3)

"Velvet Bellbottoms"

JOIN

Joins up to 8 text strings into one string, using a specified delimiter

JOIN(" ","Hello","there")

"Hello there"

LEFT

Returns the specified number of characters from the left of a text string.

LEFT("Hello world!",2)

"He"

LEFT($ITEMDESCRIPTION, 2000)

Send 2000 characters from the Description field from the start of the field.

LENGTH

Returns the number of characters in a string.

LENGTH("Hello world!")12

LTRIM

Removes all white space characters from the beginning of a text string. The text string can be a field value or quoted text string. Blank or white space includes spaces, tabs, carriage returns, and line feeds.

LTRIM(" toast ")

"toast "

PROPER

Proper title case for input text.

PROPER("This is my title.")

"This Is My Title."

REDUCE

Combines the values from a given attribute of all child items into a single value, by using a user-supplied rule.

REDUCE(FUNCTION(VARS(@X,@Y), CONCATENATE(@X,"~",@Y)),$CHILDREN.COLOR,"")

~Red~Blue~Green [assumes three child items with an attribute called COLOR, with the values Red, Blue, and Green]

REDUCELIST

Combines the values from a given lookup list into a single value, by using a user-supplied rule..

REDUCELIST(FUNCTION(VARS(@X,@Y,@Z), CONCATENATE(@X,"~",@Y)), "some list","")

~Red~Blue~Green [assumes a list child called "some list", with the names Red, Blue, and Green]

REGEXGET

Returns the first match of a regular expression, or blank if no match.

REGEXGET("Book","o+")

"oo"

REGEXMATCH

Returns true if a string contains a regular expression, false otherwise.

REGEXMATCH("Book","o+")

True

REGEXREPLACE

Finds text within a string using a regular expression and replaces all matches with new text. If the text to be replaced is in the string more than once, all matches are replaced. This is a more powerful version of REPLACE. You need to know how regular expressions work to use this. They have a learning curve, but you can read about them at http://www.regular-expressions.info/REGEXREPLACE (" Hello", "^[ \t]+", "")

"Hello" The regular expression used here does exactly what LTRIM would do, but there are much more useful ones.

REGEXREPLACE($ITEMDESCRIPTION, "'", "\"")

Remove all single quotations in the Description field and replace them with double quotations.

REPLACE

Finds text within a string and replaces all matches with new text.

REPLACE("coconut","co","wing")"wingwingnut"
REPLACE($ITEMTITLE, $ITEMBRAND, "")Remove a Brand value from the SKU Title.

REPLACEWORDLIST

Examines each word in input text, and will substitute its corresponding lookup value from the supplied list, if it exists.

REPLACEWORDLIST("mylist","Big Box of Stuff")

"Huge Box of Things" [assumes there is a list called "mylist" that contains the entries "Big" -> "Huge" and "Stuff" -> "Things"]

RIGHT

Returns the specified number of characters from the right of a text string.

RIGHT("Hello world!",2)

"d!"

RTRIM

Removes all white space characters from the end of a text string.

RTRIM(" toast ")

" toast"

STRIPHTML

Removes tags of the form <tag> from text.This will also strip out XML tags. Also, the < or > characters appearing alone will be ignored, but if both appear in a piece of text in that order, all text between them will be removed.

If some tags need to remain in place, enter a second parameter of tags, separated by a comma.

STRIPHTML ("<b>Hello</b>")

STRIPHTML("<p><b>Hello</b></p>","p")

"Hello"

"<p>Hello</p>"

STRIPHTML($ITEMDESCRIPTION)

Remove all of the HTML from the Description field.

TOLOWER

Converts text to lower case

TOLOWER("My Cat")"my cat"

TOUPPER

Converts text to upper case

TOUPPER("My Cat")"MY CAT"

TRIM

Removes all white space characters from the beginning and end of a text string.

TRIM(" toast ")"toast"

URLENCODE

Encodes a string to appear in a URL

URLENCODE("Home And Garden")

"Home%20And%20Garden"

 

Text functions allow you to disect, combine, and format text using business rules. Supported functions are listed below.

 

Prerequisites


You should be familiar with the following topics:

 

Text Functions Supported for Business Rules


View the table below for Text Functions supported for Business Rules.

Function Description Example Output
ADDTOCURRENTDATE Adds a value to the current date and returns the new date in the specified format. See GETCURRENDATE for possible date formats and date parts. Interval is just the number of days, months, years, etc. to add to the date. Use negative intervals to get dates in the past. The default templates for Google Shopping use this for feed expiration date.ADDTOCURRENTDATE("yyy-MM-dd","d",30)Returns 2007-05-25(May 25) if the current date is April 25, 2007.

CONCATENATE

Joins up to 8 text strings into one string.  There is no space or other delimiter inserted between the input strings.

CONCATENATE("Space","man")

"Spaceman"

CONCATENATE($ITEMBRAND, " ", $COLOR, " ", $SIZE)

Join together several attributes to form a title.

CONTAINS

Whether search text occurs in a string. The search is case sensitive.

CONTAINS("cookies","ook")true

DEDUP

Given a delimited list of items and the delimiter, returns a delimited list of the unique items.

DEDUP("Red,Blue,Red,Green")

"Blue,Green,Red"

GETCURRENCYCODE Returns the three character currency code abbreviation for the specified locale. Certain providers require this value to be passed in the feed. Normally the default provider templates will take care of this.GETCURRENCYCODE("en-GB")GBP
GETCURRENTDATE Returns the current date in the specified format. The full list of available formatting options is the same as that provided by Microsoft.Net. You can use their documentation on date formats. The basic options are shown below, combine them to get the desired effect. The patterns are case sensitive - "m" returns the minute not the month.GETCURRENTDATE(MMddyyyy)

03212009

GETDAYSBETWEEN

Returns the number of days between the two dates specified in the rule. If both dates are the same, the result is zero.

GETDAYSBETWEEN("05/25/2015", "06/25/2015", "MM/dd/yyyy")

31

GETDAYSSINCE

Returns the number of days between the current date and the date specified in the rule.

GETDAYSSINCE("01/01/2015","MM/dd/yyyy")

If current date is 01/16/2015, this will return 15.

GETPART

Gets the nth part of a text string, where the parts are separated by some character(s). Counts backwards from the end if a negative number is passed.

GETPART("Clothing --> Pants --> Velvet Bellbottoms","-->",3)

"Velvet Bellbottoms"

JOIN

Joins up to 8 text strings into one string, using a specified delimiter

JOIN(" ","Hello","there")

"Hello there"

LEFT

Returns the specified number of characters from the left of a text string.

LEFT("Hello world!",2)

"He"

LEFT($ITEMDESCRIPTION, 2000)

Send 2000 characters from the Description field from the start of the field.

LENGTH

Returns the number of characters in a string.

LENGTH("Hello world!")12

LTRIM

Removes all white space characters from the beginning of a text string. The text string can be a field value or quoted text string. Blank or white space includes spaces, tabs, carriage returns, and line feeds.

LTRIM(" toast ")

"toast "

PROPER

Proper title case for input text.

PROPER("This is my title.")

"This Is My Title."

REDUCE

Combines the values from a given attribute of all child items into a single value, by using a user-supplied rule.

REDUCE(FUNCTION(VARS(@X,@Y), CONCATENATE(@X,"~",@Y)),$CHILDREN.COLOR,"")

~Red~Blue~Green [assumes three child items with an attribute called COLOR, with the values Red, Blue, and Green]

REDUCELIST

Combines the values from a given lookup list into a single value, by using a user-supplied rule..

REDUCELIST(FUNCTION(VARS(@X,@Y,@Z), CONCATENATE(@X,"~",@Y)), "some list","")

~Red~Blue~Green [assumes a list child called "some list", with the names Red, Blue, and Green]

REGEXGET

Returns the first match of a regular expression, or blank if no match.

REGEXGET("Book","o+")

"oo"

REGEXMATCH

Returns true if a string contains a regular expression, false otherwise.

REGEXMATCH("Book","o+")

True

REGEXREPLACE

Finds text within a string using a regular expression and replaces all matches with new text. If the text to be replaced is in the string more than once, all matches are replaced. This is a more powerful version of REPLACE. You need to know how regular expressions work to use this. They have a learning curve, but you can read about them at http://www.regular-expressions.info/REGEXREPLACE (" Hello", "^[ \t]+", "")

"Hello" The regular expression used here does exactly what LTRIM would do, but there are much more useful ones.

REGEXREPLACE($ITEMDESCRIPTION, "'", "\"")

Remove all single quotations in the Description field and replace them with double quotations.

REPLACE

Finds text within a string and replaces all matches with new text.

REPLACE("coconut","co","wing")"wingwingnut"
REPLACE($ITEMTITLE, $ITEMBRAND, "")Remove a Brand value from the SKU Title.

REPLACEWORDLIST

Examines each word in input text, and will substitute its corresponding lookup value from the supplied list, if it exists.

REPLACEWORDLIST("mylist","Big Box of Stuff")

"Huge Box of Things" [assumes there is a list called "mylist" that contains the entries "Big" -> "Huge" and "Stuff" -> "Things"]

RIGHT

Returns the specified number of characters from the right of a text string.

RIGHT("Hello world!",2)

"d!"

RTRIM

Removes all white space characters from the end of a text string.

RTRIM(" toast ")

" toast"

STRIPHTML

Removes tags of the form <tag> from text.This will also strip out XML tags. Also, the < or > characters appearing alone will be ignored, but if both appear in a piece of text in that order, all text between them will be removed.

If some tags need to remain in place, enter a second parameter of tags, separated by a comma.

STRIPHTML ("<b>Hello</b>")

STRIPHTML("<p><b>Hello</b></p>","p")

"Hello"

"<p>Hello</p>"

STRIPHTML($ITEMDESCRIPTION)

Remove all of the HTML from the Description field.

TOLOWER

Converts text to lower case

TOLOWER("My Cat")"my cat"

TOUPPER

Converts text to upper case

TOUPPER("My Cat")"MY CAT"

TRIM

Removes all white space characters from the beginning and end of a text string.

TRIM(" toast ")"toast"

URLENCODE

Encodes a string to appear in a URL

URLENCODE("Home And Garden")

"Home%20And%20Garden"

 

0
Your rating: None Average: 4 (1 vote)
0
Your rating: None Average: 4 (1 vote)