excel - How to extract middle characters from a cell in Excel
问题描述
I need a excel function code that would enable to me extract certain characters in the middle of a cell.
So in cell A74 is:
1625362674848-cdpresent-auths_ol_mart-auths1837372
So I Need to extract "auths_ol_mart" into a separate column
I have tried this:
=MID(A2, SEARCH("-",A2) + 1, SEARCH("-",A2,SEARCH("-",A2)+1) - SEARCH("-",A2) - 1)
Now the problem is this only gets "cdpresent". I am not quite sure how this is done.
more examples include:
3837463747-cdpresent-avaya_op_history-clm1827489
I want "avaya_op_history"
3734279458-cdpresent-uk_score_app-clm9377233
I want "uk_score_app"
Thank you all
解决方案
You can use this worksheet formula:
=LEFT(MID(A1,FIND("-",A1,FIND("-",A1)+1)+1,99),FIND("-",MID(A1,FIND("-",A1,FIND("-",A1)+1)+1,99))-1)
If you use the Formula Evaluation tool, you will be able to see how this works.
If you prefer a UDF, you can use:
Function betweenDashes(S As String) As String
betweenDashes = Split(S, "-")(2)
End Function
Edit (20MAR2020)
Another formula to return the third item in the string, if you have Excel 2013+ and the FILTERXML
function:
=FILTERXML("<t><s>" & SUBSTITUTE(A1,"-","</s><s>")& "</s></t>","//s[3]")
or, if you prefer, the next to last item:
=FILTERXML("<t><s>" & SUBSTITUTE(A1,"-","</s><s>")& "</s></t>","//s[last()-1]")
推荐阅读
- javascript - JavaScript 链接事件
- android - 实例化片段的不同方式
- git - 在 Git for Windows 的安装路径中,./git-bash.exe 与 bin/bash.exe 和 bin/sh.exe 有什么区别?
- mysql - 如何在我的桌子上插入当前日期?
- ecmascript-6 - 在“base”中指定的未知插件“external-helpers”为0,这甚至意味着什么?
- android - 如何修复多个小部件使用相同的 GlobalKey?
- .net - 如何为一个 AvalonDock 选项卡项赋予特定颜色
- vue.js - Sinon stub ES6 使用 Webpack、Babel、Chai 导出的函数(Vue CLI 项目)
- postgresql - 在 Postgres 11 中的分区表上设置 autovacuum
- java - 二进制 XML 文件第 10 行:为 API 级别 19 膨胀类 com.google.android.material.button.MaterialButton 时出错