简体   繁体   English

如何在Excel中的第一个数字周围拆分/解析字符串

[英]How do I split/parse a string around the first number in Excel

I have a string in column A that is a mixture of letters and numbers. 我在A列中有一个字母和数字混合的字符串。 I want to split the string in half before the first number that shows up such that "abc123" becomes "abc" in column B and "123" in column C. 我想在显示的第一个数字之前将字符串分成两半,使得“abc123”在列B中变为“abc”而在列C中变为“123”。

If there's any sort of pattern, eg always 3 letters.....or only 3 or 4 letters, for example then you can achieve more easily but for any number of letters (assuming that numbers always follow letters) you can use this formula in B2 (which is simpler than the suggested formula in topcat3's link, I think) 如果有任何类型的模式,例如总是3个字母.....或者只有3个或4个字母,那么你可以更轻松地实现但是对于任意数量的字母(假设数字总是跟着字母)你可以使用这个公式在B2中(我认为这比topcat3链接中建议的公式简单)

=LEFT(A2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A2&1234567890))-1)

and then this formula in C2 然后在C2中的这个公式

=REPLACE(A2,1,LEN(B2),"")

Note that this last formula returns the number part as a text value - if you want it to be numeric add +0 to end of formula (but you will lose any leading zeroes) 请注意,最后一个公式将数字部分作为文本值返回 - 如果您希望它是数字,请将+0添加到公式的末尾(但是您将丢失任何前导零)

Just wanted to contribute a slight variation on Barry's formulas. 只是想对巴里的公式做出轻微的修改。 Slightly easier to understand in my opinion but a little bit more difficult to use: 在我看来稍微容易理解,但使用起来有点困难:

You can use this array formula to find the starting position + 1 of the first number: 您可以使用此数组公式查找第一个数字的起始位置+ 1:

{=MIN(IFERROR(FIND({1,2,3,4,5,6,7,8,9,0},A2),""))}

entered with ctrl+alt+enter to make it an array formula. 使用ctrl + alt + enter输入,使其成为数组公式。

Then you can use that number to split the first part off of the string: 然后你可以使用那个数字来分割字符串的第一部分:

=LEFT(A2,B2-1)

And then you can use REPLACE() to get rid of the first part(the letters) off of the string. 然后你可以使用REPLACE()去除字符串的第一部分(字母)。

=REPLACE(A2,1,LEN(C2),"")

You should accept Barry's answer and not this one because his is easier to use and more concise. 你应该接受Barry的答案,而不是这个,因为他更容易使用,更简洁。 But just wanted to add a variation in my quest to understand how Barry's formula worked. 但我只是想在我的追求中添加一个变体,以了解巴里的公式是如何运作的。

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

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