Search code examples
excelstringexcel-formulagoogle-sheetsgoogle-sheets-query

Get a string out of a string of dash-separated values


I have a table that looks like this, (row 1 acts solely as titles):

 |----------A----------|---------B--------|--------C---------|---------D--------|
1|  String of Strings  |     Thing  1     |     Thing  2     |     Thing  3     |
 |---------------------|------------------|------------------|------------------|
2|   q1-22ll-o7kp-e... |         q1       |       22ll       |     ??????       |
 |---------------------|------------------|------------------|------------------|

Using this guide, I've been able to successfully fill in cells B2 and C2:

B2: =LEFT(A2, SEARCH("-",A2,1)-1)

C2: =MID(A2, SEARCH("-",A2) + 1, SEARCH("-",A2,SEARCH("-",A2)+1) - SEARCH("-",A2) - 1)

I'm trying to understand the pattern for D2, though. I don't fully grasp what C2 is doing -- how would I build upon C2's formula so that I can get the third thing in my String of Strings?

I figure once I see the pattern for D2, I'll be able to continue going for E2, F2, etc.

I'm hoping to find a solution that works on either Google Sheets or Excel.


Solution

  • With data in A2, in B2 enter:

    =TRIM(MID(SUBSTITUTE($A2,"-",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
    

    and copy across:

    enter image description here