2

我需要一个 excel 公式来查找 excel 单元格中最后两个下划线之间的文本:

IE

AAA_BBB_CCC_DDDD_E => DDDD
AAA_BBB_CCC_DDD_EEE_E => EEE
AAA_BBB_CCC_DDD_EEE_F_ => F
AAA_BBB_CCC_DDD_EE_GGGGGGGGGG => EE
AAA_BBB_CCC_DDD_EEE_FFF_GGGGGGGGGGGG_H => GGGGGGGGGGGG

我得到的公式是基于最后一个索引: EXCEL LAST INDEX OF

=RIGHT(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1),LEN(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1))-SEARCH("@",SUBSTITUTE(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1),"_","@",LEN(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1))-LEN(SUBSTITUTE(LEFT(A2,SEARCH("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))-1),"_","")))))

我需要让这不那么复杂,有什么想法吗?

4

3 回答 3

8

尝试这个

=TRIM(LEFT(RIGHT(SUBSTITUTE(H3,"_",REPT(" ",100)),200),100))

请注意,如果任何段可能超过 50 个字符,请相应增加 100 和 200 个数字

于 2012-11-06T10:26:43.313 回答
2

Here's another variation.....

=MID(A1,FIND("^",SUBSTITUTE(A1,"_","^",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))-1))+1,SUM(FIND("^",SUBSTITUTE(A1,"_","^",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))-{0,1}))*{1,-1})-1)

于 2012-11-06T14:22:23.703 回答
2

克里斯的解决方案非常简洁 - 但是,我也想出了一个替代方案。

=MID(A1,1+SEARCH("@", 
     SUBSTITUDE(A1,"_","@",LEN(A1)-1-LEN(SUBSTITUDE(A1,"_","")))),
     SEARCH("@",SUBSTITUDE(A1,"_","@",LEN(A1)-LEN(SUBSTITUDE(A1,"_",""))))-1-
     SEARCH("@",SUBSTITUDE(A1,"_","@",LEN(A1)-1-LEN(SUBSTITUDE(A1,"_","")))))
于 2012-11-06T10:44:22.693 回答