Skip to main content

Rule box category Change string length

Learn how to use rule boxes in the category Change string length to control the length of your attribute values based on word or character count.

Introduction

The category Change string length contains all rule boxes that can help you control the length of your attribute values based on word or character count. Knowing the length of your values, you can cut or extend your values with the rule boxes in this category.

change_string_length.png

This category can be divided into several subgroups. In the following sections, you can learn how to use the rule boxes of each subgroup:

Count the number of characters or words

The category Change string length contains the rule boxes Character count and Word count to let you count the number of characters and words in your attribute values.

Character count

The Character count rule box counts the number of characters or bytes in a text value and overwrites the current value with the result.

Tip

You can also find out the number of characters in your attribute values using the Length Distribution section of the Analyzer feature. See Analyze your data in Data View.

  1. Take the steps from Add a rule box to add the Character count rule box.

    character_count.png
  2. In the drop-down menu, choose whether the rule box should count and output the number of bytes or characters.

  3. Select Save.

For example, you have the following values in the color attribute. See how the Character count rule box counts the number of characters and overwrites the current values with the result if you select character in the drop-down menu:

color (before)

color (after)

black

5

red

3

0

Word count

The Word count rule box counts the number of words in a text value and overwrites the current value with the result.

  1. Take the steps from Add a rule box to add the Word count rule box.

    word_count_box.png
  2. Select Save.

For example, you have the following values in the color attribute. See how the Word count rule box counts the number of words and overwrites the current values with the result:

color (before)

color (after)

black and white

3

red

1

0

Cut or extend text based on string length

The rule box category Change string length contains the rule boxes Cut first characters, Cut last characters, Cut last words, Extend Text, Trim Category Tree, Trim to 70 characters, and Trim to 150 characters to let you reduce or increase the length of text values in your site.

Tip

You can also use the Shorten Text and Lengthen Text data services to achieve similar results. See Shorten, lengthen, or create text from attributes with AI services.

Cut first characters

The Cut first characters rule box removes a desired number of characters at the beginning of your text values, including when it means cutting off a part of a word. This rule box can be useful if you need to meet a length limit for an attribute's values or remove the same part of text added at the beginning of all values.

You can also use the Shorten Text data service to achieve similar results. See Shorten, lengthen, or create text from attributes with AI services.

  1. Take the steps from Add a rule box to add the Cut first characters rule box.

    cut_first_characters.png
  2. In the Use drop-down menu, choose whether the rule box should cut the number of characters or bytes at the beginning of each value.

  3. In the input field, enter a desired number of characters or bytes that the rule box should cut off. If a value is shorter than the number of characters in this field, the rule box empties the value.

  4. Select Save.

For example, you have the following values in the title attribute and want to cut off the first 15 characters in each value because the sale is over. You can achieve this with the following setup of the Cut first characters rule box:

Use: character, input field: 15

title (before)

title (after)

SALE! 50% OFF! Socks

Socks

50% OFF Cap

 

SALE! 50% OFF! Pajama Pants

Pajama Pants

Cut last characters

The Cut last characters rule box does a hard cut when a text value reaches a desired character limit, including when it means cutting off a part of a word. This rule box can be useful if you need to meet a length limit for an attribute's values.

You can also use the Shorten Text data service to achieve similar results. See Shorten, lengthen, or create text from attributes with AI services.

  1. Take the steps from Add a rule box to add the Cut last characters rule box.

    cut_last_characters.png
  2. In Cut last characters if length exceeds ... characters, enter a desired character limit to let the rule box cut off all following characters when a text length reaches the limit.

  3. Select Save.

For example, you have the following values in the title attribute and want each value to stay within the limit of 15 characters. You can achieve this with the Cut last characters rule box by entering 15 as the limit:

title (before)

title (after)

Red Socks

Red Socks

Pillow Case with Fluffy Eco-Feathers

Pillow Case wit

Pajama Pants for Kids

Pajama Pants f

Tip

Compare these results to how the Cut last words rule box works. See Cut last words.

Cut last words

The Cut last words rule box cuts off all words that exceed a desired character limit in a text value and ensures your text values don't break off in the middle of a word, unlike the Cut last characters rule box. This rule box can be useful if you need to meet a length limit for an attribute's values.

You can also use the Shorten Text data service to achieve similar results. See Shorten, lengthen, or create text from attributes with AI services.

  1. Take the steps from Add a rule box to add the Cut last words rule box.

    cut_last_words.png
  2. In Cut last words if length exceeded, enter a desired character limit to let the rule box cut off all words outside the character limit.

  3. Select Save.

For example, you have the following values in the title attribute and want each value to stay within the limit of 15 characters. At the same time, you need each value to end with a full word. You can achieve this with the Cut last words rule box by entering 15 as the limit:

title (before)

title (after)

Red Socks

Red Socks

Pillow Case with Fluffy Eco-Feathers

Pillow Case

Pajama Pants for Kids

Pajama Pants

Tip

Compare these results to how the Cut last characters rule box works. See Cut last characters.

Extend Text

The Extend Text rule box lets you increase the length of a text value by setting a desired character limit and, if a value is shorter, filling the rest of it with a desired text until it reaches the limit. If a value doesn't reach the character limit with the added text string, the rule box repeats the string as many times as necessary to reach the character limit. This rule box can be useful if you need to meet a minimum length requirement for an attribute's values.

You can also use the Lengthen Text data service to achieve similar results. See Shorten, lengthen, or create text from attributes with AI services.

  1. Take the steps from Add a rule box to add the Extend Text rule box.

    extend_text.png
  2. In length of the output string, enter a desired character limit that the rule box should meet when adding and repeating a string.

    Note

    If a current value exceeds the character limit you set in this field, the Extend Text rule box doesn't add any text to the value and doesn't cut it to fit the limit.

  3. In fill character(s), enter the string you want the rule box to add and repeat in your text value until it reaches the desired character limit.

  4. In the drop-down menu, select where you want to add the string within the value:

    1. left adds the string at the beginning of the current value.

    2. right adds the string at the end of the current value.

    3. both adds the string both at the beginning and end of the current value.

  5. Select Save.

For example, you have the following values in the short_description attribute and want each value to be exactly 30 characters long. Some values are shorter than that, so you want to add a piece of text to extend the length of those values and reach the desired 30-character limit. You can achieve this with the following setup of the Extend Text rule box:

length of the output string: 30, fill character(s): . Next-Day Shipping, drop-down menu: right

short_description (before)

short_description (after)

Red Socks

Red Socks. Next-Day Shipping.

Note

There is a space character at the end of the value.

Pillow Case with Fluffy Eco-Feathers

Pillow Case with Fluffy Eco-Feathers

Pajama Pants for Kids

Pajama Pants for Kids. Next-Da

Trim Category Tree

The Trim Category Tree rule box cuts off category items at the > delimiter if they exceed a defined character limit. This rule box can be useful if you need to meet a length limit for the category attribute.

  1. Take the steps from Add a rule box to add the Trim Category Tree rule box.

    trimming_category.png
  2. In Cut last categories at the delimiter '>' if length exceeds ... characters, enter a desired character limit for your categories.

  3. Select Save.

For example, you have the following values in the category attribute and want each value to stay within the limit of 50 characters. You can achieve this with the Trim Category Tree rule box by entering 50 as the limit:

category (before)

category (after)

Apparel & Accessories > Shoe Accessories

Apparel & Accessories > Shoe Accessories

Home & Garden > Linens & Bedding > Bedding > Blankets

Home & Garden > Linens & Bedding > Bedding

Apparel & Accessories > Clothing > Underwear & Socks

Apparel & Accessories > Clothing

Trim to 70 characters

Google accepts values for the brand attribute if they are no longer than 70 characters.

The Trim to 70 characters rule box does a hard cut when a text value reaches a 70-character limit, including when it means cutting off a part of a word.

  1. Take the steps from Add a rule box to add the Trim to 70 characters rule box.

    trim_to_70_characters.png
  2. Select Save.

For example, you have the following values in the brand attribute and want each value to stay within the limit of 70 characters. You can achieve this with the Trim to 70 characters rule box:

brand (before)

brand (after)

Natural History Museum and Royal Philharmonic Orchestra (RPO) Collaboration

Natural History Museum and Royal Philharmonic Orchestra (RPO) Collabo

Harley-Davidson Motor Company

Harley-Davidson Motor Company

Trim to 150 characters

Google accepts values for the title attribute if they are no longer than 150 characters.

The Trim to 150 characters rule box does a hard cut when a text value reaches a 150-character limit, including when it means cutting off a part of a word.

  1. Take the steps from Add a rule box to add the Trim to 150 characters rule box.

    trim_to_150_characters.png
  2. Select Save.

For example, you have the following values in the title attribute and want each value to stay within the limit of 150 characters. You can achieve this with the Trim to 150 characters rule box:

title (before)

title (after)

Kitchen Container for Organic Waste - Pine Wood & Stainless Steel for Organic Leftovers - Dishwasher-Safe - Removable Lid - Removable Insert

Kitchen Container for Organic Waste - Pine Wood & Stainless Steel for Organic Leftovers - Dishwasher-Safe - Removable Lid - Removable Insert

Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen

Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up a

Extract specific parts of values with split string rule boxes

The category Change string length contains the rule boxes Split String, Split String for PLA, Split String & Filter, and Split String and Count Items to let you shorten the values of attributes containing category paths, lists, or other data types that involve multiple data points. Using these rule boxes, you can split each text value into data points using a delimiter and preserve only the needed parts of the value in an attribute.

All split string rule boxes follow a specific method of numbering data points within strings using delimiters. This method supports both positive and negative numbers. For example, when applying any split string rule box to the category path Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds, the platform assigns the following numbers to each step of the category path:

Positive numbers

0

>

1

>

2

>

3

Category path

Animals & Pet Supplies

Pet Supplies

Dog Supplies

Dog Beds

Negative numbers

-4

-3

-2

-1

Using these numbers and the greater-than sign (>) as a delimiter in a split string rule box, you can let the platform know which data points you want to retrieve and what character splits the string into data points.

Tip

You can use both positive and negative numbers of data points in a split string rule box. However, if you need to retrieve a couple of data points at the end of a string, and the strings in your attribute don't always have the same number of data points, you should use negative numbers.

Split String

The Split String rule box uses delimiters and analyzes the values of an attribute to extract and save only those parts of the values you need.

  1. Take the steps from Add a rule box to add the Split String rule box.

    Use the Split String rule box to shorten strings in your values and delete unnecessary info
  2. Enter the delimiter character that splits your string into multiple data points in Splitter.

    Note

    The platform never displays the splitter in the output if you extract only one data point from the value. To see the splitter in the output value, you need to extract at least two data points.

  3. In From, enter the number of the data point from which the platform should start extracting information. The expected input format for this field is a digit.

    See the previously shown numbering example to identify the number of your desired data point.

  4. Enter how many data points you want the platform to extract from your values in Items.

    The expected input format for this field is a digit. Only positive numbers are acceptable.

    Note

    If you leave Items empty, the platform extracts all data points of the string, starting with the data point specified in From.

  5. Select Save.

For example, you want to shorten a category path and keep only the first 2 category items in the category attribute. You can achieve this with the following setup of the Split String rule box:

Splitter: >, From: 0, Items: 2

category (before)

category (after)

Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds

Animals & Pet Supplies > Pet Supplies

Home & Garden > Linens & Bedding > Bedding > Blankets

Home & Garden > Linens & Bedding

Apparel & Accessories > Clothing

Apparel & Accessories > Clothing

The Split String rule box can also let you extract information from a long text. For example, you want to extract product colors from the description attribute where all descriptions use the same template: The manufacturer uses only natural and hypoallergenic materials to produce these [products]. Colors available: color1, color2, and color3. Size range: size1, size2, and size3. You can extract colors from these descriptions with the following setup of two Split String rule boxes:

rule box 1: Splitter: ". Size range:", From: "0", Items: "1"; rule box 2: Splitter: "Colors available: ", From: "1", Items: "1"

Note

There is a space character at the end of the input value Colors available: .

description (before)

description (intermediate values before applying the second rule box)

description (after)

The manufacturer uses only natural and hypoallergenic materials to produce these dog beds. Colors available: black, gray, white, green, yellow, and lilac. Size range: XS, S, M, L, XL, and XXL

The manufacturer uses only natural and hypoallergenic materials to produce these dog beds. Colors available: black, gray, white, green, yellow, and lilac

black, gray, white, green, yellow, and lilac

The manufacturer uses only natural and hypoallergenic materials to produce these dog blankets. Colors available: brown, gray, green, and blue. Size range: XS, S, L, and XXL

The manufacturer uses only natural and hypoallergenic materials to produce these dog blankets. Colors available: brown, gray, green, and blue

brown, gray, green, and blue

The manufacturer uses only natural and hypoallergenic materials to produce these climbing trees for cats. Colors available: beige, gray, white, black, and brown. Size range: M, L, and XL

The manufacturer uses only natural and hypoallergenic materials to produce these climbing trees for cats. Colors available: beige, gray, white, black, and brown

beige, gray, white, black, and brown

Split String for PLA

The Split String for PLA rule box uses delimiters and analyzes the values of an attribute to extract and save only those parts of the values you need. If the rule box finds no delimiter in a value, it empties the value to prevent you from sending incorrect data to your export channels.

  1. Take the steps from Add a rule box to add the Split String for PLA rule box.

    Use the Split String for PLA rule box to split strings and empty the values of such products where the platform found no splitter character
  2. Enter the delimiter character that splits your string into multiple data points in Splitter.

    Note

    The platform never displays the splitter in the output if you extract only one data point from the value. To see the splitter in the output value, you need to extract at least two data points.

  3. In Male regex and Female regex, enter regular expressions to search your values and replace the matching parts with a relevant gender option.

    See the previously shown numbering example to identify the number of your desired data point.

    Note

    If you enter 0 in From, the platform starts extracting information from your first data point and, after finding no splitter character in the string, returns the entire string as if it consisted of one data point only.

    To have the Split String for PLA rule box empty the values that contain no splitter characters, specify any number in From but for 0 and negative numbers.

  4. Enter how many data points you want the platform to extract from your values in Items.

    The expected input format for this field is a digit. Only positive numbers are acceptable.

    Note

    If you leave Items empty, the platform extracts all data points of the string, starting with the data point specified in From.

  5. Select Save.

Google accepts the following values for the gender attribute:

Rule box and setup

category (before)

category (after)

Splitter: >, From: 1, Items: 2

Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds

Pet Supplies > Dog Supplies

Apparel & Accessories > Clothing > Activewear

Clothing > Activewear

Arts & Entertainment --- Event Tickets

Arts & Entertainment --- Event Tickets

Splitter: >, From: 1, Items: 2

Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds

Pet Supplies > Dog Supplies

Apparel & Accessories > Clothing > Activewear

Clothing > Activewear

Arts & Entertainment --- Event Tickets

See Split String for more information.

Split String & Filter

The Split String & Filter rule box uses delimiters and analyzes the values of an attribute to extract and save only those parts of the values you need. Additionally, it lets you limit the length of your resulting value. If the resulting value exceeds its maximum length, the rule box doesn't leave chunks of data points in the value. If a part of a data point doesn't fit into the character limit, the platform omits the data point from the resulting value entirely.

  1. Take the steps from Add a rule box to add the Split String & Filter rule box.

    Use the Split String & Filter rule box to split strings and limit the length of the output
  2. Enter the delimiter character that splits your string into multiple data points in Splitter.

    Note

    The platform never displays the splitter in the output if you extract only one data point from the value. To see the splitter in the output value, you need to extract at least two data points.

  3. In From, enter the number of the data point from which the platform should start extracting information. The expected input format for this field is a digit.

    See the previously shown numbering example to identify the number of your desired data point.

  4. Enter how many data points you want the platform to extract from your values in Items.

    The expected input format for this field is a digit. Only positive numbers are acceptable.

    Note

    If you leave Items empty, the platform extracts all data points of the string, starting with the data point specified in From.

  5. In max Length, specify a character limit for your resulting value.

  6. Select Save.

Compare the output values of the Split String and Split String & Filter rule boxes applied to the same category attribute:

Rule box and setup

category (before)

category (after)

Splitter: >, From: 0, Items: 3

Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds

Animals & Pet Supplies > Pet Supplies > Dog Supplies

Apparel & Accessories > Clothing > Activewear

Apparel & Accessories > Clothing > Activewear

Arts & Entertainment > Concerts, Shows, & Other Events > Event Tickets

Arts & Entertainment > Concerts, Shows, & Other Events > Event Tickets

Splitter: >, From: 0, Items: 3, max Length: 50

Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds

Animals & Pet Supplies > Pet Supplies

Apparel & Accessories > Clothing > Activewear

Apparel & Accessories > Clothing > Activewear

Arts & Entertainment > Concerts, Shows, & Other Events > Event Tickets

Arts & Entertainment

See Split String for more information.

Split String and Count Items

The Split String and Count Items rule box analyzes the values of an attribute to split them into separate data points and count how many data points each value contains. The rule box uses a delimiter to count the number of data points within a value and overwrites the value with the resulting total.

  1. Take the steps from Add a rule box to add the Split String and Count Items rule box.

    Use the Split String and Count Items rule box to let the platform count the number of data points (items) in your strings and output the result in the attribute
  2. In Please select Separator!, enter the character that splits your value into data points.

    Note

    If a value doesn't contain the defined delimiter character, the rule box considers it a value with one data point and outputs 1.

  3. Select Save.

For example, you have the following values in the category attribute and want to learn how many category items each product's category has. You can achieve this with the Split String and Count Items rule box by entering > as the delimiter:

category (before)

category (after)

Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds

4

Home & Garden > Linens & Bedding > Bedding > Blankets

4

Apparel & Accessories > Clothing

2

Apparel & Accessories ~ Clothing

1

Add a static or dynamic value if it fits a character limit

The category Change string length contains the rule boxes Add Value if Fits and Add Column if Fits to let you add a static or dynamic value to an attribute if the current value can fit the added string without exceeding a character limit.

See Static vs. dynamic values for a definition of static and dynamic values.

Add Value if Fits

The Add Value if Fits rule box lets you add a word or phrase to your current values if the overall length of the resulting value doesn't exceed a desired character limit.

  1. Take the steps from Add a rule box to add the Add Value if Fits rule box.

    Add Value if Fits
  2. In Mode, select where you want to add a string within the current value:

    1. append adds the string at the end of the current value. To separate it from the rest of the text, add a space character at the beginning of your input in ???.

    2. prepend adds the string at the beginning of the current value. To separate it from the rest of the text, add a space character at the end of your input in ???.

  3. Enter the string you wish to append or prepend to your current values in Text.

  4. Enter the desired character limit in Max Length.

    Note

    If a current value exceeds the character limit you set in this field, the Add Value if Fits rule box doesn't add any text to the value and doesn't cut it to fit the limit.

  5. Select Save.

For example, you have the following values in the title attribute and want to add ORDER NOW at the end of each title if the overall length of the resulting value doesn't exceed 150 characters. You can achieve this with the following setup of the Add Value if Fits rule box:

Mode: append, Text: " ORDER NOW", Max Length: 150

Note

A space character at the beginning of the input in Text separates the added text from the current value.

title (before)

title (after)

Kitchen Container for Organic Waste - Pine Wood & Stainless Steel for Organic Leftovers - Dishwasher-Safe - Removable Lid - Removable Insert

Kitchen Container for Organic Waste - Pine Wood & Stainless Steel for Organic Leftovers - Dishwasher-Safe - Removable Lid - Removable Insert ORDER NOW

Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen

Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen

The value Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen exceeds the 150-character limit, so the rule box doesn't add the text ORDER NOW.

Add Column if Fits

The Add Column if Fits rule box lets you add the values of another attribute to your current values if the overall length of the resulting value doesn't exceed a desired character limit.

  1. Take the steps from Add a rule box to add the Add Column if Fits rule box.

    add_column_if_fits.png
  2. Select the attribute you want to add to your current values in Column.

  3. In Mode, select where you want to add the values of the chosen attribute within the current values:

    1. append adds the string at the end of the current value.

    2. prepend adds the string at the beginning of the current value.

  4. In Max Length, specify a character limit for the resulting values.

  5. Optionally, you can add some text before or after the added attribute value:

    1. Enter the desired text in the input field your text.

    2. Open the drop-down menu on the left to select Text Before or Text After and choose whether to add the text before or after the added attribute value.

  6. Select Save.

For example, you have the following values in the title attribute and want to add the color of the product at the end of each title if the overall length of the resulting value doesn't exceed 150 characters. You can achieve this with the following setup of the Add Column if Fits rule box:

add_column_if_fits_setup_example.png

color (no changes)

title (before)

title (after)

Green

Kitchen Container for Organic Waste - Pine Wood & Stainless Steel for Organic Leftovers - Dishwasher-Safe - Removable Lid - Removable Insert

Kitchen Container for Organic Waste - Pine Wood & Stainless Steel for Organic Leftovers - Dishwasher-Safe - Removable Lid - Removable Insert - Green

Orange

Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen

Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen

The value Medium-Size Kitchen Bin for Compost with Lid Indoor 8L - Green Plastic Container for Organic Waste - Ventilation Holes Preventing Humidity Build-Up and Odor Spreading to Kitchen is over 150 characters long, so the rule box doesn't append the value Orange from color.