Finding and replacing text in Airtable
  • 26 Aug 2024
  • 4 Minutos para leer
  • Oscuro
    Ligero
  • PDF

Finding and replacing text in Airtable

  • Oscuro
    Ligero
  • PDF

The content is currently unavailable in Spanish. You are viewing the default English version.
Resumen del artículo

Plan availability

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 )

360101549513find-1.jpg

File names always follow the same structure in Airtable, and look like this:

1500000450422find-2.jpg

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() and SEARCH() 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.

1500000450522nesting-1.jpg

1500000450542nesting-2.gif

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.


¿Te ha sido útil este artículo?