Apr 20, 2020 10:26 AM
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?
Apr 20, 2020 07:32 PM
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.
Apr 20, 2020 09:21 PM
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),
""
)
)
Apr 20, 2020 09:38 PM
If you really want a JavaScript solution, you can use various string methods.
substr()
to extract the first 256 characterslastIndexOf()
to find the position of the last space before the 256th characterslice()
to get the first portion of the tweet (based on the position identified in step 2.slice()
to get the second portion of the tweet (based on the position identified in step 2.Feb 15, 2021 11:31 AM
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.
Feb 15, 2021 11:56 AM
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.
Feb 15, 2021 02:14 PM
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…