Table of Contents
String formulas: change, check and combine text
Updated
by Desirée M
String formulas change text, check what's in it and put pieces of text together. Use them in a Formulas block to tidy up a name, look for a word in an answer, count characters, count the picks of a multiple-choice question or build a link.
To add the block and write your first formula, see How to use the Formulas block: a beginner's guide. Prefer watching? The Formulas video tutorial in the Landbot Academy builds formulas step by step.
Which string formulas can you use?
The Formulas block has twelve string formulas:
● Concat(text, text, …): joins text, Fields and numbers into one text.
● Upper(text), Lower(text), Title(text) and Capitalize(text): all capitals, all lowercase, a capital at the start of every word, or a capital only at the start of the text.
● Contains(text, word): True when the text includes the word. It's case sensitive.
● Length(text): the number of characters, spaces included.
● Replace(text, old, new): replaces every match: Replace("Via Roma 12", " ", "+") gives Via+Roma+12.
● Slice(text, start, end): a part of the text. Positions count from 0 and the end isn't included: Slice("Mario", 0, 3) gives Mar.
● Split(text, separator): cuts the text into a list.
● ToString(value): turns a number into text.
● Encode(text): makes text safe for a web address: spaces become %20.
How to use a string formula in a Formulas block
Most string formulas give back text, so pick SUCCESS / ERROR under Block outputs and save the result in a TEXT Field. Contains answers True or False, so pick TRUE / FALSE to branch on it. Length gives back a number, so save it in a NUMBER Field. Write fixed text in double quotes, such as "gluten", and Fields with @.
The examples below come from one pizzeria agent, Forno Rosa, which takes delivery orders. It asks for the visitor's name, extra toppings, notes for the kitchen and the delivery address.
Title and Capitalize: tidy up a name
Title puts a capital at the start of every word and lowercases the rest, which suits names typed in a hurry. An Ask a question block saves the name in @name, and a Formulas block saves Title(@name) in @name_clean: mario ROSSI becomes Mario Rossi. Capitalize only capitalizes the first letter and lowercases the rest, so the same name becomes Mario rossi.
Contains and Length: check what the visitor wrote
Contains looks for a word in an answer, and Length counts its characters. Forno Rosa asks "Any notes for the kitchen? Type them here, or type no." and saves the answer in @notes. A Formulas block checks IsGreater(Length(@notes), 100) and a second one checks Contains(Lower(@notes), "gluten"), both with TRUE / FALSE:
● Note over 100 characters, such as a 106-character delivery instruction: "That's a long note! Please keep it under 100 characters." and the question comes back.
● Note that mentions gluten, such as No onions, Gluten free please: "Good news: we have a gluten-free base, and we'll use it for your pizza."
● Any other note: the agent goes on to ask for the address.

"gluten". Wrap the answer in Lower() and write the word in lowercase, as in Contains(Lower(@notes), "gluten").Split and Length: count the picks of a multiple-choice question
Split cuts text into a list, and Length counts the items in the list. A Buttons block with Multiple choices on saves the picks as one text by default, separated by a comma and a space, such as Mushrooms, Olives. Forno Rosa counts them with Length(Split(@toppings, ", ")) and saves 2 in @extras, a NUMBER Field.

ToString and Replace: show a price with a comma
ToString turns a number into text, and Replace swaps characters in it, so a price can be written the way Italian customers read it. Forno Rosa works out the price with Math formulas, Sum(12.5, Product(@extras, 1.5)), saves it in @price, a NUMBER Field, and then saves Replace(ToString(@price), ".", ",") in @price_it:
● 2 extras: "Thanks, Mario Rossi! Order FR-MAR: a pizza with Mushrooms, Olives, 15,5 €."
● 1 extra: "Thanks, Ana! Order FR-ANA: a pizza with Basil, 14 €."
Slice, Upper and Concat: build an order reference
Concat joins pieces of text, and Slice takes a part of one. Forno Rosa builds a short order reference from the first three letters of the name with Concat("FR-", Slice(Upper(@name), 0, 3)) and saves it in @order_ref: mario ROSSI gets FR-MAR and ana gets FR-ANA. Put Upper inside Slice, as in this formula. Concat also joins numbers: Concat("FR-", 42) gives FR-42.
Encode: put an answer in a link
Encode turns spaces, commas and other symbols into codes a web address accepts. Forno Rosa asks "What's the delivery address?" and builds a map link for the rider with Concat("https://www.google.com/maps/search/?api=1&query=", Encode(@address)). For Via Roma 12, Milano, the address part of the link becomes Via%20Roma%2012%2C%20Milano, and the agent sends the link as a clickable message: "Map for our rider: https://www.google.com/maps/search/?api=1&query=Via%20Roma%2012%2C%20Milano".
Which formulas work well with string formulas?
String formulas are often combined with four other types:
● Comparison formulas check text, such as IsGreater with Length, or IsEqual with Lower.
● Logical formulas combine several text checks into one.
● Array formulas work with the list Split gives back.
● Regex formulas check that text follows a pattern, such as an order number.