字符串在Excel中分离 [英] String Separate in Excel

查看:211
本文介绍了字符串在Excel中分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mozilla-nss-3.11.4-0.7

gdb-10.12-1.5.2

glibc-dcc-atv-1.0.3-10.6

我想在下一个BCD单元格中分开它

i want to separate it too in the next B C D cell

mozilla-nss      3.11.4       0.7

gdb              10.12        1.5.2

glibc-dcc-atv    1.0.3        10.6

现在我可以使用左,右和查找功能来做,但不太顺利

right now i can use left , right and find function to do it but not quite work well

我使用

LEFT(B33,FIND(".",B33)-2) =B cell

RIGHT(B33,FIND(".",B33))   =C Cell

RIGHT(D33,FIND("-",D33)-1)  = D Cell

答案是不正确的任何人都可以帮助我纠正我的功能谢谢

answer is not right anyone can Help me correct my function thank you

推荐答案

这里的关键点使得任务变得困难 - 我们需要用作分隔符最后两个连字符字符串,并保持完整。对于这种情况, ARRAY公式是最佳拍摄。我的解决方案如下:

The key point here which makes the task difficult - we need to use as separators LAST TWO hyphens in the string, and remain all the rest intact. For such cases ARRAY formulas is the best shot. My solution is below:


  1. 名称6列开始A1:String | MAX - | 2nd MAX - | Str1 | Str2 | Str3

  2. 将您的值放在A栏,从 A2

  3. B2( MAX - ):键入公式 = MAX(IFERROR(SEARCH( - ,$ A2,ROW(INDIRECT(1:& LEN )),0)),但按 CTRL + SHIFT + ENTER 而不是通常的 kbd> - 这将定义一个ARRAY公式,并将导致 {} 括号(但不要手动输入!)。

  4. C2( 2nd MAX - ):输入公式 = MAX(IFERROR(SEARCH( - ,$ A2,ROW(INDIRECT(1: ; LEN($ A2)))),0)* IF(IFERROR(SEARCH( - ,$ A2,ROW(INDIRECT( 1: &安培; LEN($ A2)))),0)= MAX( IFERROR(SEARCH( - ,$ A2,ROW(INDIRECT(1:& LEN($ A2)))),0)),0,1)) kbd> CTRL + SHIFT + ENTER

  1. Name 6 columns starting A1: String | MAX "-" | 2nd MAX "-" | Str1 | Str2 | Str3
  2. Put your values in Column A starting at A2.
  3. B2 (MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
  4. C2 (2nd MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)*IF(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)=MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)),0,1)) and again press CTRL+SHIFT+ENTER.

我们将在字符串中获取最后两个连字符的位置。其余的是简单的 - 普通的LEFT / MID / RIGHT的东西:

Thus we'll obtain positions of LAST TWO hyphens in the string. The rest is easy - ordinary LEFT / MID / RIGHT stuff:


  1. D2: = LEFT($ A2,$ C2-1) ENTER

  2. E2: = MID($ A2,$ C2 + 1 ,$ B2- $ C2-1) ENTER

  3. F2: = RIGHT($ A2 ,LEN($ A2) - $ B2) ENTER

  4. 自动填充 B:F

  1. D2: =LEFT($A2,$C2-1), ENTER.
  2. E2: =MID($A2,$C2+1,$B2-$C2-1), ENTER.
  3. F2: =RIGHT($A2,LEN($A2)-$B2), ENTER.
  4. Autofill B:F.

如果临时列B:C是不需要的 - 您应该将D中的引用替换为B: :C内容(即在 = LEFT($ A2,中用A2实际公式)替换 $ A2 导致TOO复杂的ARRAY公式,仍然在做他们的工作 - 但是即使对于创作者也很难理解)

If temporary columns B:C are unwanted - you should replace references to them in D:F for B:C contents (i.e. replace $A2 in =LEFT($A2, with A2 actual formula), but this will result in TOO complicated ARRAY formulas, still doing their job - but difficult to understand the next day even for the creator)

对于上述解决方案 - 也许可能会改进或简化,但我非常熟悉这样的 ROW ... INDIRECT 从我不得不分析兆字节的统计数据的时间的结构,所以对我来说,这很简单创建左/右。无论如何,它似乎工作。

As for the above solution - perhaps it might be improved or simplified, but I'm pretty much familiar with such ROW...INDIRECT constructions from times I had to analyze megabytes of statistic data, so for me it's just as easy as create LEFT / RIGHT. Anyway, it seems to work.

为了方便起见,我的示例文件被共享: https://www.dropbox.com/s/p49x32t3a0igtby/StringHyphensSeparate.xlsx

For your convenience my sample file is shared: https://www.dropbox.com/s/p49x32t3a0igtby/StringHyphensSeparate.xlsx

希望这是有帮助的)

添加 - 2个更简化的解决方案来查找LAST TWO连字符(其余步骤与上述相同):

ADDITION - 2 more simplified solutions to find LAST TWO hyphens (the rest of steps is the same as above):


  • 更简单的ARRAY公式:

  • More simple ARRAY formulas:


  • B2 MAX - ):键入公式 = MAX(IF(MID($ A2,ROW(INDIRECT(1:& LEN($ A2))) 1)= - ,ROW(INDIRECT(1:& LEN($ A2))),0)),但按 CTRL + SHIFT + ENTER 而不是通常的 ENTER - 这将定义一个ARRAY公式,并将导致 {}

  • C2( 2nd MAX - ):键入公式 = LARGE(IF(MID($ A2,ROW(下载ECT( 1: &安培; LEN($ A2))),1)= - ,ROW(INDIRECT( 1: &安培; LEN($ A2))),0),2)再次按 CTRL + SHIFT + ENTER

  • B2 (MAX "-"): type the formula =MAX(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
  • C2 (2nd MAX "-"): type the formula =LARGE(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0),2) and again press CTRL+SHIFT+ENTER.

使用 SUBSTITUTE 函数的常规公式:


  • B2( MAX - ):键入公式 = SEARCH(@,SUBSTITUTE($ A2, - ,@,LEN($ A2) LEN(SUBSTITUTE($ A2, - ,)))) ENTER

  • C2(第二个MAX - ):键入公式 = SEARCH(@,SUBSTITUTE($ A2, - ,@,LEN($ A2)-LEN(SUBSTITUTE $ A2, - ,)) - 1)) ENTER

  • B2 (MAX "-"): type the formula =SEARCH("@",SUBSTITUTE($A2,"-","@",LEN($A2)-LEN(SUBSTITUTE($A2,"-","")))), ENTER.
  • C2 (2nd MAX "-"): type the formula =SEARCH("@",SUBSTITUTE($A2,"-","@",LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))-1)), ENTER.

解决方案的 SUBSTITUTE 解决方案的关键是它只能替换某些匹配的实例<强>,即只有第二或第三连字符。通过 SUBSTITUTE 公式再次确定连字符的总数:公式:原始字符串的长度MINUS长度的字符串,所有连字符替换为空字符串: LEN($ A2)-LEN(SUBSTITUTE($ A2, - ,)
这里还有一个诀窍 - 虽然我们应该保持原始的字符串完整,但我们仍然可以做任何事情因此,我们用 @ 替换连字符,然后搜索 @ 在临时字符串中。

The key for SUBSTITUTE solution is that it may replace only certain instances of matches, i.e. only 2nd or 3rd hyphen. The overall number of hyphens is determined again via SUBSTITUTE formula: length of original string MINUS length of string with ALL hyphens replaced to empty strings: LEN($A2)-LEN(SUBSTITUTE($A2,"-",""). One more trick here - while we should remain the original string intact, we still MAY do anything with it for intermediate solutions! Thus, we replace the hyphen with @, and then search for @ in temporary string.

所有上述解决方案都在工作,选择你喜欢/理解更好,希望这也有助于理解数组公式,因为在同一个任务有两种不同的方法。

All the above solutions are working, choose what you like / understand better. Hope that will also help in understanding array formulas, since for the same task there are 2 different approaches.

我更新了示例文件,以包含最后2个示例+没有中间步骤的结果megaform,链接是一样的,位于上面。祝你好运!

I updated the example file to include the last 2 examples + resulting megaformulas without intermediate steps, link is the same and located above. Good luck!

这篇关于字符串在Excel中分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆