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

前端 未结 4 494
旧时难觅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:35

    Modify thy below formula and try:

    =MID(A1,FIND(" ",A1,1)+1,FIND(" ",A1,FIND(" ",A1)+1)-FIND(" ",A1,1)-1)
    

    0 讨论(0)
  • 2021-01-17 02:38

    If you make all of the spaces the same width as the entire original string you can easily pick out the second word with MID and TRIM it back to its original.

    'first word
    =trim(left(substitute(a2, " ", rept(" ", len(a2))), len(a2)))
    'second word
    =trim(mid(substitute(a2, " ", rept(" ", len(a2))), len(a2)*1, len(a2)))
    'third word
    =trim(mid(substitute(a2, " ", rept(" ", len(a2))), len(a2)*2, len(a2)))
    'last word
    =trim(right(substitute(a2, " ", rept(" ", len(a2))), len(a2)))
    

    The len(a2)*1 (starting point of MID) is the dimension that determines which word is extracted.

    0 讨论(0)
  • 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("<t><s>"&SUBSTITUTE(TRIM(A1)," ","</s><s>")&"</s></t>","//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.

    0 讨论(0)
  • 2021-01-17 02:54

    You can search the next part of the string by using mid to get the remainder of the string after the first and then searching that substring.

    Value                  Description         Formula
    This is a test string  Original string     #N/A
    5                      Pos of first space  =SEARCH(" ",A2)
    is a test string       Rest of string      =MID(A2,A3+1,LEN(A2))
    3                      Rel pos 2nd space   =SEARCH(" ",A4)
    is                     Extracted “is”      =MID(A2,A3+1,A5-1)
    
    Combined formula:
    =MID(A2,SEARCH(" ",A2)+1,SEARCH(" ",MID(A2,SEARCH(" ",A2)+1,LEN(A2)))-1)
    

    This method becomes much more complex if you want to find more than the first two occurrences of a delimiter, but it can be simpler than the other one if you have a delimiter other than space.

    0 讨论(0)
提交回复
热议问题