问题
I have this formula. This works great but fails when there are 5 characters including the dot.
For example,
abcdefgh.pdf =TRIM(LEFT(A1,LEN(A1)-4)) gives me abcdefgh xyz.xlsx =TRIM(LEFT(A2,LEN(A2)-4)) gives me xyz.
Is there a formula that looks for the last dot and trims everything after the last dot?
回答1:
Try this formula to get rid of the last dot and everything after
=LEFT(A1,LOOKUP(2^15,FIND(".",A1,ROW(INDIRECT("1:"&LEN(A1)))))-1)
If there's only ever one dot as per your examples then you only need
=LEFT(A1,FIND(".",A1)-1)
回答2:
This formula works well
=TRIM(RIGHT(SUBSTITUTE(A1,".",REPT(" ",100)),100))
It replaces each period with 100 spaces and then returns the right 100 characters and trims it. You can also replace "." with "\" to get the filename.
Credit to NBVC at excelforum.com
回答3:
Could try below formula.
=SUBSTITUTE(A1,"."& RIGHT(A1,LEN(A1)-FIND("|",SUBSTITUTE(A1,".","|",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),"")
This works for file extensions with 2 to 7 character file extensions with full paths and namespaces notation in filename.
you could also use
=RIGHT(A1,LEN(A1)-FIND("|",SUBSTITUTE(A1,".","|",LEN(A1)-LEN(SUBSTITUTE(A1,".","")))))
to find the extension of the file.
来源:https://stackoverflow.com/questions/16063463/triming-extension-from-filename-in-excel