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.
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.
Take the steps from Add a rule box to add the Character count rule box.
In the drop-down menu, choose whether the rule box should count and output the number of bytes or characters.
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 |
|
red |
|
|
Word count
The Word count rule box counts the number of words in a text value and overwrites the current value with the result.
Take the steps from Add a rule box to add the Word count rule box.
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 |
|
red |
|
|
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.
Take the steps from Add a rule box to add the Cut first characters rule box.
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.
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.
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:
title (before) | title (after) |
---|---|
SALE! 50% OFF! Socks |
|
50% OFF Cap |
|
SALE! 50% OFF! 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.
Take the steps from Add a rule box to add the Cut last characters rule box.
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.
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 |
|
Pillow Case with Fluffy Eco-Feathers |
|
Pajama Pants for Kids |
|
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.
Take the steps from Add a rule box to add the Cut last words rule box.
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.
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 |
|
Pillow Case with Fluffy Eco-Feathers |
|
Pajama Pants for Kids |
|
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.
Take the steps from Add a rule box to add the Extend Text rule box.
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.
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.
In the drop-down menu, select where you want to add the string within the value:
left adds the string at the beginning of the current value.
right adds the string at the end of the current value.
both adds the string both at the beginning and end of the current value.
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:
short_description (before) | short_description (after) |
---|---|
Red Socks |
NoteThere 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 |
|
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.
Take the steps from Add a rule box to add the Trim Category Tree rule box.
In Cut last categories at the delimiter '>' if length exceeds ... characters, enter a desired character limit for your categories.
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 |
|
Home & Garden > Linens & Bedding > Bedding > Blankets |
|
Apparel & Accessories > Clothing > Underwear & Socks |
|
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.
Take the steps from Add a rule box to add the Trim to 70 characters rule box.
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 |
|
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.
Take the steps from Add a rule box to add the Trim to 150 characters rule box.
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 |
|
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 |
|
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 |
|
|
|
|
|
|
|
Category path |
|
|
|
| |||
Negative numbers |
|
|
|
|
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.
Take the steps from Add a rule box to add the Split String rule box.
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.
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.
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.
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:
category (before) | category (after) |
---|---|
Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds |
|
Home & Garden > Linens & Bedding > Bedding > Blankets |
|
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:
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 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 climbing trees for cats. Colors available: beige, gray, white, black, and brown. Size range: M, L, and XL |
|
|
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.
Take the steps from Add a rule box to add the Split String for PLA rule box.
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.
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.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.
Select Save.
Google accepts the following values for the gender attribute:
Rule box and setup | category (before) | category (after) |
---|---|---|
Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds |
| |
Apparel & Accessories > Clothing > Activewear |
| |
Arts & Entertainment --- Event Tickets |
| |
Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds |
| |
Apparel & Accessories > 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.
Take the steps from Add a rule box to add the Split String & Filter rule box.
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.
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.
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.
In max Length, specify a character limit for your resulting value.
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) |
---|---|---|
Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds |
| |
Apparel & Accessories > Clothing > Activewear |
| |
Arts & Entertainment > Concerts, Shows, & Other Events > Event Tickets |
| |
Animals & Pet Supplies > Pet Supplies > Dog Supplies > Dog Beds |
| |
Apparel & Accessories > Clothing > Activewear |
| |
Arts & Entertainment > Concerts, Shows, & Other Events > Event Tickets |
|
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.
Take the steps from Add a rule box to add the Split String and Count Items rule box.
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
.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 |
|
Home & Garden > Linens & Bedding > Bedding > Blankets |
|
Apparel & Accessories > Clothing |
|
Apparel & Accessories ~ Clothing |
|
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.
Take the steps from Add a rule box to add the Add Value if Fits rule box.
In Mode, select where you want to add a string within the current value:
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 ???.
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 ???.
Enter the string you wish to append or prepend to your current values in Text.
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.
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:
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 |
|
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.
Take the steps from Add a rule box to add the Add Column if Fits rule box.
Select the attribute you want to add to your current values in Column.
In Mode, select where you want to add the values of the chosen attribute within the current values:
append adds the string at the end of the current value.
prepend adds the string at the beginning of the current value.
In Max Length, specify a character limit for the resulting values.
Optionally, you can add some text before or after the added attribute value:
Enter the desired text in the input field your text.
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.
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:
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 |
|
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.