How can I use excel function (LEFT/RIGHT/MID) to extract string which sorrounded by same symbol?

前端 未结 4 542
旧时难觅i
旧时难觅i 2021-01-17 02:13

My string is like; eg: A2 column : This is a test string.

Where I want to extract word \'is\'. I know I have to use MID function wi

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 02:44

    Assuming you are not required to use ONLY those functions:

    If you have a version of Excel that includes the FILTERXML function, you can use this formula to extract the 2nd word:

    =INDEX(FILTERXML(""&SUBSTITUTE(TRIM(A1)," ","")&"","//s"),2)
    

    If your version does not have that function, you can use:

    =INDEX(TRIM(MID(SUBSTITUTE(TRIM(A1)," ",REPT(" ",99)),seq_99,99)),2)
    

    where seq_99 is a Named Formula:

    seq_99 refers to:  =IF(ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))=1,1,(ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))-1)*99)
    

    Both split the string into an array, and then use the INDEX function to return the desired element in that array.

    You may need to modify the SUBSTITUTE portion of the functions to handle both spaces and hyphens, or any other delimiters you may have.

提交回复
热议问题