Formulas and Functions

Formulas and Functions

Ask for help with your formula and find examples of how others use formulas and functions to solve a similar problem.

Isolating all text to the right of a character (e.g. "-") in a string

✭✭
edited 11/16/22 in Formulas and Functions

Hello Smart People -


I'm parsing a string using helper columns. I want to return all text to the right of my last "-". For example, QA-IS-OPS would return OPS, and QA-ARC-RM would return RM.


Is there a simple way to do this?


Thank you!

Tags:

Best Answer

  • Community Champion
    Answer ✓

    First we need to find out how many there are.

    =LEN([Column Name]@row) - LEN(SUBSTITUTE([Column Name]@row, "-", "")


    Now that we know how many we have, we can replace the last one with a unique character. For this you are going to want to choose something that is definitely NEVER going to be anywhere else within the string. In my example I will use CHAR(10) which is a line break.

    =SUBSTITUTE([Column Name]@row, "-", CHAR(10), LEN([Column Name]@row) - LEN(SUBSTITUTE([Column Name]@row, "-", ""))


    Now that we have a unique value as the last character to exclude, we can use a FIND to determine how many characters from the left that unique character is.

    =FIND(CHAR(10), SUBSTITUTE([Column Name]@row, "-", CHAR(10), LEN([Column Name]@row) - LEN(SUBSTITUTE([Column Name]@row, "-", "")))


    Subtracting that number from the total number of characters:

    =LEN([Column Name]@row) - FIND(CHAR(10), SUBSTITUTE([Column Name]@row, "-", CHAR(10), LEN([Column Name]@row) - LEN(SUBSTITUTE([Column Name]@row, "-", "")))


    Tells us how many characters to pull for the RIGHT function:

    =RIGHT([Column Name]@row, LEN([Column Name]@row) - FIND(CHAR(10), SUBSTITUTE([Column Name]@row, "-", CHAR(10), LEN([Column Name]@row) - LEN(SUBSTITUTE([Column Name]@row, "-", ""))))


    Plug that in and let me know how it goes.


    It could also be simplified if we can work from certain assumptions such as it will always be after the 2nd "-" and the first "-" is always the 3rd character in the string. The above provides for the most amount of flexibility so that you can have has many hyphens as you want and the number of characters throughout doesn't matter.

Answers

Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the Formula Handbook template!

Trending in Formulas and Functions