reduce_words

Returns as many characters as possible, starting from the beginning of a string and counting up to a delimiter, while staying within max_length. If the string is already within max_length, the function returns string exactly as it was passed in.

Always counts in the natural direction of the advertiser’s locale. For example, if the advertiser’s language is English, this function counts from left to right.

Note: This function is only available in Templates and can’t be used in Reporting.

Syntax

reduce_words(string, max_length, delimiter, [delimiter], ...)
Learn how to Use functions in custom columns.

Parameters

  • string: A feed string attribute such as DESCRIPTION, or a static string surrounded by quotes such as "My great shoe store".
  • max_length: the maximum number of characters in the output string. Can be any of the following:
    • 0 (zero).
    • A positive integer, such as 5.
    • An expression or function that returns a positive number.
  • delimiter: A single character such as " " or a static string such as "store". If you specify more than one delimiter, the function uses the delimiter that yields the longest string fitting within max_length.

Examples

  • reduce_words("My great shoe store", 10, " ") returns "My great". To calculate this string, the function follows these steps:
    1. Finds the last instance of the delimiter (which is the space between "shoe" and "store").
    2. Counts backwards 10 characters to see if it has reached the beginning of the string.
    3. In this example, the function doesn't reach the beginning, so it moves to the previous instance of the delimiter, the space between "great" and "shoe", and counts backwards 10 characters.
    4. The function reaches the beginning of the string before finishing the count, so it returns everything preceding the delimiter.
  • reduce_words(DESCRIPTION, 15, " and"). If the feed specifies "Low prices and wide selection" for the DESCRIPTION attribute, this function returns "Low prices". Note that the delimiter includes a space before "and". Without the space in the delimiter, the function would return "Low prices ".
  • reduce_words(DESCRIPTION, 15, " "). If the feed specifies "Low prices" for the DESCRIPTION attribution, the function returns "Low prices".

Related links

Was this helpful?

How can we improve it?

Need more help?

Try these next steps:

true
Search
Clear search
Close search
Google apps
Main menu
9842673134130258612
true
Search Help Center
true
true
true
true
true
5055977
false
false