+ Reply to Thread
Results 1 to 11 of 11

Deconcatenating a list of strings

  1. #1
    Registered User
    Join Date
    07-18-2016
    Location
    San Diego
    MS-Off Ver
    2007
    Posts
    13

    Deconcatenating a list of strings

    My problem involves deconcatenating a list of strings (filenames) that all have the following structure:

    ABD DEF-G.HIJ.ext

    I'd like the final format to at least split the string on either side of the hyphen, and remove or separate the .ext component.

    If the 'bar' symbol:'|' is a cell separator in the spreadsheet, the deconcatenated list (of ~350) filenames would have this structure in the spreadsheet:

    | ABC DEF | - | G.HIJ | .ext | Please see attachment for a clearer image.

    I have done similar string splits when I was working with Excel every day, but with unuse, have forgotten some details.
    Attached Images Attached Images

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Deconcatenating a list of strings

    (How to) Upload a Workbook directly to the Forum
    (please do not post pictures or links to worksheets)
    • Click Advanced next to Quick Post button at the bottom right of the editor box.
    • Scroll down until you see "Manage Attachments",
    • Click the "Choose" button at the upper left (upload from your computer).
    • Select your file, click "open", click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Close the Attachment Manager window.
    • Click "Submit Reply"
    Note: Please do not attach password protected workbooks/worksheets
    Ensure to disable any Workbook Open/Autorun macros before attaching!
    Ben Van Johnson

  3. #3
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Deconcatenating a list of strings

    You could try the following four formulas - assuming your data is in cell A1.

    B1 =LEFT($A1,FIND("-",$A1)-1)
    C1 =MID(A1,FIND("-",$A1),1)
    D1 =MID(A1,FIND("-",$A1)+1,FIND(".ext",$A1)-(FIND("-",$A1)+1))
    E1 =RIGHT($A1,4)

    There may be many other ways, but these work on the limited sample base you provided.

    I hope this helps, please let me know!

    Regards,

    David


    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".


  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Deconcatenating a list of strings

    Hi, welcome to the forum

    It is always better if you give more than 1 example of what you are dealing with.

    I'd like the final format to at least split the string on either side of the hyphen
    That kinda tells me you want this split further?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    07-18-2016
    Location
    San Diego
    MS-Off Ver
    2007
    Posts
    13

    Re: Deconcatenating a list of strings

    David:
    Your formulae worked excellently on the one "ABC DEF..." filename I put in A1. The problem is that I have about 350 of these filenames to deconcatenate or split apart. I didn't say in my original post that I don't need the extension, just the strings to the immediate left and right of the hyphen (but not the hyphen itself). If my screenshot came through they would be just TITLE and AUTHOR.

    I've not been able to configure your formulae in a way that would separate a column of 350 of these filenames. I'm going to attempt to attach a worksheet with 40 filenames. I omitted the extension because I could easily do so and I don't need it. And hopefully save a step.

    Thanks for your help,
    Pallando
    Attached Files Attached Files
    Last edited by Pallando_II; 07-20-2016 at 06:52 PM.

  6. #6
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Deconcatenating a list of strings

    I think that there is a mistake in entry on row 8 that has --. Without that, this should work in B1 and fill down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Enter in C1 and fill down
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,913

    Re: Deconcatenating a list of strings

    Or try this ...

    Formula in B1:

    =LEFT(A1,LEN(A1)-LEN(C1)-1)

    Formula in C1:

    =TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",255)),255))

  8. #8
    Registered User
    Join Date
    07-18-2016
    Location
    San Diego
    MS-Off Ver
    2007
    Posts
    13

    Re: Deconcatenating a list of strings

    Thanks, Newdoverman. I thought I knew Excel reasonably well at one time (90's, 00's), but I couldn't even follow your logic on this one. If you have the time and inclination, could you give me a nickel's explanation of your algorithm?

  9. #9
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Deconcatenating a list of strings

    The process that I followed is as follows. There were instances in your list with more than one - . I think that the double -- is a mistake so didn't make an effort to take care of that.
    The first part of the first formula "IF(LEN(SUBSTITUTE(A1,"-"," "))-LEN(A1)=1" tests to see if there is more than one - in the string. The substitute replaces the - with two spaces. If the length of the substitution is longer than the original contents of A1 by 1 then there was only 1 - in the string. If the difference is 1 then the TRUE part of the IF statement "LEFT(A1,FIND("-",A1)-1)" is calculated. This simply searches for the - and returns the characters to the left of the -. The -1 eliminates the - from the result.

    If the result of "IF(LEN(SUBSTITUTE(A1,"-"," "))-LEN(A1)=1" is greater than 1 the FALSE part of the IF statement "LEFT(SUBSTITUTE(A1,"-","~",2),FIND("~",SUBSTITUTE(A1,"-","~",2))-1))" comes into play. The SUBSTITUTE with the ~ replaces the - with a ~. This will force the second - in the string to be used in the FIND so that the second - determines what the LEFT function will return.

    Seeing that your examples had a maximum of two - characters I did not make any accommodation for more than that. I have no idea how many different arrangements of - with and without spaces and other characters exist so just used your example as truly representative of your data.

    Having separated the left part of the string, that value can be used to isolate the right side of the string. That is what the second formula does.

    If you find that there are extraneous spaces, you can surround both formulae with the TRIM function to get rid of unnecessary spaces.

    There may be methods that are more simple given but that is what I came up with in a limited amount of time.
    I hope that this at least helps.

  10. #10
    Registered User
    Join Date
    03-26-2016
    Location
    São Paulo - Brazil
    MS-Off Ver
    2016
    Posts
    48

    Re: Deconcatenating a list of strings

    Pallando_II

    See if this way helps

    =TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",LEN(A1))),LEN(A1)))

    Decio

  11. #11
    Registered User
    Join Date
    07-18-2016
    Location
    San Diego
    MS-Off Ver
    2007
    Posts
    13

    Re: Deconcatenating a list of strings

    deciog

    Your code works well. I had to figure that you only gave me one-half of what I needed since I could only get the right half of my files. "Try LEFT and see what happens. OK, there's the left side." Your code is more compact that some code presented and also seems to take care of any number of "-" 's which divide left from right, although any double hyphen like in my Row-8 is a mistake.

    Thanks,
    Pallando_II
    Last edited by Pallando_II; 07-21-2016 at 04:32 PM. Reason: correction

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. search list of strings in another list
    By niukvba in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2014, 02:01 PM
  2. [SOLVED] search for parts of strings in another list of strings
    By marioroter in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-17-2013, 12:28 PM
  3. Skakes in the Summer
    By lowryda777 in forum Excel General
    Replies: 2
    Last Post: 06-27-2012, 10:29 AM
  4. Replies: 4
    Last Post: 02-22-2011, 02:01 PM
  5. Get unique list of strings
    By kapilrakh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2009, 09:27 PM
  6. [SOLVED] List of ADO GUID strings
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-22-2006, 07:50 AM
  7. How to find number of pairs of strings from list of strings?
    By greg_overholt in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-27-2006, 06:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1