简体   繁体   English

excel中基于数组拆分字符串

[英]Split String Based on Array in excel

I have excel cells like the one below我有 excel 个像下面这样的单元格

WYONG RD BRYANT DR TUGGERAH 2259 CENTRAL COAST (LGA) NSW

I want to grab any sort of Road, Street, Drive, Highway etc. in one column and then the intersecting road in another column.我想在一列中抓取任何类型的道路、街道、车道、高速公路等,然后在另一列中抓取相交的道路。 SO for the above cell my desired output would be:所以对于上面的单元格,我想要的 output 将是:

Column 1: WYONG RD第 1 栏:WYONG 路

Column 2: Bryant DR专栏 2:科比 DR

The code below brings the two roads into one column but I want to separate them but am having some difficulty on how to.下面的代码将两条道路合并为一列,但我想将它们分开,但在操作上遇到了一些困难。

=INDEX(IFERROR(LEFT(H2,SEARCH({" DR"," HWY"," ST"," CRK"," BND"," LN"," AV"," AVE"," MTWY"," RD"," CT"},H2)+3),""),MATCH(MAX(LEN(IFERROR(LEFT(H2,SEARCH({" DR"," HWY"," ST"," CRK"," BND"," LN"," AV"," AVE"," MTWY"," RD"," CT"},H2)+2),""))),LEN(IFERROR(LEFT(H2,SEARCH({" DR"," HWY"," ST"," CRK"," BND"," LN"," AV"," AVE"," MTWY"," RD"," CT"},H2)+2),"")),0)))

With MS365, you could use:使用 MS365,您可以使用:

在此处输入图像描述

Formula in A3 : A3中的公式:

=LET(X,FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s"),TRIM(FILTERXML("<t><s>"&TEXTJOIN(" ",,IF(MMULT(--(X={"DR";"HWY";"ST";"CRK";"BND";"LN";"AV";"AVE";"MTWY";"RD";"CT"}),SEQUENCE(11,,,0)),X&"</s><s>",X))&"</s></t>","//s")))

I tried to check your formula but, unfortunately, it throws me an error.我试图检查你的公式,但不幸的是,它给了我一个错误。 Thus, I spent some time and came up with the following solution:因此,我花了一些时间想出了以下解决方案:

Say, the input string is in the A2 cell and the outputs are in the B2 and C2 cells.比如说,输入字符串在A2单元格中,输出在B2C2单元格中。 Thus, the formulas can be as follows:因此,公式可以如下:

For B2 :对于B2

=LEFT(A2,
MIN(IFERROR(SEARCH(" DR",  A2)+2,1000000),
    IFERROR(SEARCH(" HWY", A2)+3,1000000),
    IFERROR(SEARCH(" ST",  A2)+2,1000000),
    IFERROR(SEARCH(" CRK", A2)+3,1000000),
    IFERROR(SEARCH(" BND", A2)+3,1000000),
    IFERROR(SEARCH(" LN",  A2)+2,1000000),
    IFERROR(SEARCH(" AV",  A2)+2,1000000),
    IFERROR(SEARCH(" AVE", A2)+3,1000000),
    IFERROR(SEARCH(" MTWY",A2)+4,1000000),
    IFERROR(SEARCH(" RD",  A2)+2,1000000),
    IFERROR(SEARCH(" CT",  A2)+2,1000000)))

For C2 :对于C2

=LEFT(SUBSTITUTE(A2,B2&" ",""),
MIN(IFERROR(SEARCH(" DR",  SUBSTITUTE(A2,B2&" ",""))+2,1000000),
    IFERROR(SEARCH(" HWY", SUBSTITUTE(A2,B2&" ",""))+3,1000000),
    IFERROR(SEARCH(" ST",  SUBSTITUTE(A2,B2&" ",""))+2,1000000),
    IFERROR(SEARCH(" CRK", SUBSTITUTE(A2,B2&" ",""))+3,1000000),
    IFERROR(SEARCH(" BND", SUBSTITUTE(A2,B2&" ",""))+3,1000000),
    IFERROR(SEARCH(" LN",  SUBSTITUTE(A2,B2&" ",""))+2,1000000),
    IFERROR(SEARCH(" AV",  SUBSTITUTE(A2,B2&" ",""))+2,1000000),
    IFERROR(SEARCH(" AVE", SUBSTITUTE(A2,B2&" ",""))+3,1000000),
    IFERROR(SEARCH(" MTWY",SUBSTITUTE(A2,B2&" ",""))+4,1000000),
    IFERROR(SEARCH(" RD",  SUBSTITUTE(A2,B2&" ",""))+2,1000000),
    IFERROR(SEARCH(" CT",  SUBSTITUTE(A2,B2&" ",""))+2,1000000)))

Note that the second formula relies on the first formula output.请注意,第二个公式依赖于第一个公式 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM