简体   繁体   中英

Remove special characters and numbers in a number string

I would like to cleanup some string that contains special characters and numbers.

I tried some formula in achieving this with a string that contains letters and numbers:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"0",""),"1",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9",""),";#;#",", "),";#","")

示例 1

However, my main problem here is that I would like to clean up a string which contains numbers as shown below:

示例 2

Is there anyway I can achieve the above screenshot by tweaking the formula I used for the first example? As the formula in the first example would only delete all the characters in the string.

Interesting challenge, and it might be done smarter/shorter, but I wanted to give it a try using formulas only (another option I could think of is using PowerQuery):


So bascially in B2 put:

=TEXTJOIN(", ",TRUE,TEXT(FILTERXML("<t><s>"&SUBSTITUTE(A2,";#","</s><s>")&"</s></t>","//s[string-length(text())>3]"),"0000"))

Results:

在此处输入图像描述


Note: It's an array formula and needs to be confirmed through Ctrl Shift Enter

And untill MS introduces some sort of SPLIT formula to the DA-formula family I think FILTERXML is going to be your best bet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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