博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Excel lastindex of a substring
阅读量:7262 次
发布时间:2019-06-29

本文共 1354 字,大约阅读时间需要 4 分钟。

 

I think I get what you mean. Let's say for example you want the right-most \ in the following string (which is stored in cell A1):

Drive:\Folder\SubFolder\Filename.ext

To get the position of the last \, you would use this formula:

=FIND("@",SUBSTITUTE(A1,"\","@",(LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))/LEN("\")))

That tells us the right-most \ is at character 24. It does this by looking for "@" and substituting the very last "\" with an "@". It determines the last one by using

(len(string)-len(substitute(string, substring, "")))\len(substring)

In this scenario, the substring is simply "\" which has a length of 1, so you could leave off the division at the end and just use:

=FIND("@",SUBSTITUTE(A1,"\","@",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))

Now we can use that to get the folder path:

=LEFT(A1,FIND("@",SUBSTITUTE(A1,"\","@",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))

Here's the folder path without the trailing \

=LEFT(A1,FIND("@",SUBSTITUTE(A1,"\","@",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))-1)

And to get just the filename:

=MID(A1,FIND("@",SUBSTITUTE(A1,"\","@",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))+1,LEN(A1))

However, here is an alternate version of getting everything to the right of the last instance of a specific character. So using our same example, this would also return the file name:

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

转载地址:http://moddm.baihongyu.com/

你可能感兴趣的文章
页面关键词Meta Keywords和描述Description的优化作用
查看>>
android 图片压缩
查看>>
【转】Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)
查看>>
仿微沟道效应,主要actionbar有些知识
查看>>
ASP.NET MVC3 入门指南之数据验证[源码RAR下载]
查看>>
14.7-3
查看>>
Linux的概念与体系
查看>>
Request中的各种方法
查看>>
java中Date与String的相互转化
查看>>
span 文本内容超过宽度自动换行
查看>>
编码问题
查看>>
SessionListener失败,退出
查看>>
Sightseeing Cows(最优比率环)
查看>>
Android导航菜单横向左右滑动并和下方的控件实现联动
查看>>
C# 多线程,论多核时代爱恨情仇
查看>>
linux系统新建用户ssh远程登陆显示-bash-4.1$解决方法
查看>>
APACHE POI教程 --java应用程序用POI与Excel交互
查看>>
firefox浏览器批处理插件imacros
查看>>
inno setup检查是否已经安装
查看>>
【转】 在Eclipse中使用JUnit4进行单元测试(中级篇)
查看>>