triming extension from filename in Excel

China☆狼群 提交于 2019-12-14 01:16:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!