Help

Re: How to split a string into two separate columns without breaking words

1493 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Zach_Swetz
4 - Data Explorer
4 - Data Explorer

I have a column with text that I send out as tweets.

Sometimes this column has more then 256 characters and cannot post to Twitter.

In those situations, I’m hoping to split the column into two so that I can send out two separate tweets.

I was using SPLIT(text) however that splits based on character count and sometimes it breaks the words in half.

I’m hoping to split the text without breaking the words.

Unsure how to use it with Airtable Scripting block. Can anyone help me use this within Airtable?

6 Replies 6

Welcome to the community @Zach_Swetz!

You need to share an example of how you are presently using Split() and the “text” you are passing into it for anyone to be able to help you.

Is there a reason you are using Scripting block to do this instead of formula fields?

Assuming that your tweet will always be considerably less than 490 words, and that the words are less than 20 characters, you can do this with formula fields.

For the first tweet, if the tweet is over 256 characters, use the tweet up to the first space after the 236th character:

IF(
  LEN({tweet}) > 256,
  LEFT(
    {tweet}, 
    FIND(" ", {tweet},LEN({tweet})-20)
  ),
  {tweet}
)

For the second tweet, use the rest of the string after the space identified.:

IF(
  LEN({tweet}) > 256,
  REPLACE(
    {tweet},
    1, 
    FIND(" ", {tweet},LEN({tweet})-20),
    ""
  )
)


If you really want a JavaScript solution, you can use various string methods.

  1. Use substr() to extract the first 256 characters
  2. Use lastIndexOf() to find the position of the last space before the 256th character
  3. Use slice() to get the first portion of the tweet (based on the position identified in step 2.
  4. Use slice() to get the second portion of the tweet (based on the position identified in step 2.

Can you help clarify what to input here? I’m trying to get a field that splits my “caption” field automatically into tweets as you indicate. Does the Formula field need to be named Tweet? Thanks for your help.

Welcome to the Airtable community!

In my formula fields, {tweet} happens to be the name of the original text field containing the text. You can replace it with {caption} or whatever is the name of your original text field, as long as you replace it everywhere it occurs. You can also name the formula field whatever you want. The name of the formula field doesn’t affect the formula itself.

Really appreciate your help! Here’s my table: https://airtable.com/tbl8tj3zOUjDHDmzK/viwht9IEhrsIx7m1w?blocks=hide

Looks like the 2nd Formula works (field = Tweet 2), but the first Tweet field populates the whole Caption field still…