- 26 Aug 2024
- 4 Minutos para leer
- Impresión
- OscuroLigero
- PDF
Finding and replacing text in Airtable
- Actualizado en 26 Aug 2024
- 4 Minutos para leer
- Impresión
- OscuroLigero
- PDF
All plan types | |
Platform(s) | Web/Browser, Mac app, and Windows app |
Related reading |
This article covers how to find, search for, and replace text within a string to streamline your team's and organization's work.
Using FIND() and SEARCH() in Airtable
Using FIND() and SEARCH()
The FIND
and SEARCH
functions locate any character in a string of text and tells you where the first occurrence exists in that string. While SEARCH
will only provide the character position if it finds one, FIND
will provide the number zero if it finds nothing at all.
This makes FIND
a better candidate for most formulas because it offers a result that will prevent multi-function formulas from displaying an error. Aside from that, and their names, these functions are otherwise identical. For simplicity, we'll focus on using FIND
. Let's begin with an example string of text to work with:
Hello, world!
If you wanted to find the position of the comma in that string you'd just use the FIND function like this:
FIND ( "," , "Hello, world!" )
In this case, the FIND function will provide the following result:
6
We get the number 6 because the comma in the example is the 6th character in that string of text. If we, instead, looked for the exclamation point the formula would provide the number 13 instead. A common use of FIND
is to extract the file name from an attachment in a record using a formula like this:
LEFT ({Attachment Field},FIND( "(" ,{Attachment Field}) -1 )
File names always follow the same structure in Airtable, and look like this:
We can therefore use FIND
to identify a character in that file name string, like the opening parenthesis, as a sort of placeholder in order to extract only the file name from that entire string. Here's the formula again for easy reference:
LEFT({Attachment Field},FIND("(", {Attachment Field})-1)
FIND
looks for the opening parenthesis and returns the number that it falls on within the string. LEFT
then uses that number to know how many characters to extract from the entire string. This creates a dynamic way to always extract the right amount of character for any file name!
Note that this formula only accounts for attachment fields with a single file attached.
Using REPLACE() and SUBSTITUTE() in Airtable
Note
Before reading and understanding the section below, you may want to read the section about the
FIND()
andSEARCH()
functions available here.
Using REPLACE() and SUBSTITUTE()
The REPLACE
and SUBSTITUTE
functions accomplish very similar but different tasks. Put simply, you use REPLACE
to replace a single instance of some amount of text (e.g. a name) and you use SUBSTITUTE
when you want to replace them all. Take this text string for example:
His name was George.
What if his name wasn't George but, rather, Billy? We can use the REPLACE
function to fix that:
REPLACE("His name was George", 14, 6, "Billy")
That formula would provide the result we want:
His name was Billy
The SUBSTITUTE function can do the same thing:
SUBSTITUTE("His name was George", "George", "Billy")
In this case, using SUBSTITUTE
makes more sense because George only appears once in the text and it doesn't require us to locate any exact character positions. If George appeared multiple times and we only wanted to change one instance of George to Billy, using REPLACE
would make more sense.
You can use both functions on text fields in your base like this:
REPLACE({Text Field}, 14, 6, "Billy")
SUBSTITUTE({Text Field}, "George", "Billy")
SUBSTITUTE, on its own, will successfully replace every instance of George with Billy in every record using that text field. If it finds nothing, it will replace nothing and leave the text as-is.
REPLACE, on the other hand, will replace the characters at the specified location with Billy in every record. You probably won't want that and will need to locate where the first instance of George begins if you want to ensure consistent replacements. This formula meets those criteria:
REPLACE({Text Field}, FIND("George", {Text Field}), 6, "Billy")
In this case, we only need to find the starting location of George because we know the count will always remain the same. After all, George is and always will be a six letter name. When you want to replace a single instance some text, you only need one other function to do it consistently throughout all your records.
Nesting functions in Airtable
Nesting functions
In order to substitute out different values within the same formula, you're able to nest these functions similarly to how you would nest an IF statement.
For example, if you wanted to substitute out vertical pipes ||
for double forward slashes //
, and periods .
with commas ,
you could nest those two substitutions together in the same formula.
SUBSTITUTE(SUBSTITUTE ({Field Name}, "||" , "//" ),"." , "," )
Notice that only the inner-most function references the field name, while the outer function works by substituting the result of the function nested within it.
See the example below for a more dramatic example of a complex nested substitute formula.
While the formula above may look intimidating, it's actually quite straightforward. The inner-most function SUBSTITUTE({name},"%","%25")
references the field where the target text exists. Then, each of the other nested functions above it substitute out text from the result of each of the functions within it.