仅保留字符串中的数字/删除所有非数字 [英] Keep only numbers in a string / remove all non-numbers

查看:8
本文介绍了仅保留字符串中的数字/删除所有非数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串列,我只需要每个字符串中的数字,例如

I have a string column where I only need to the numbers from each string, e.g.

A-123  -> 123
456    -> 456
7-X89  -> 789   

如何在 PowerQuery 中做到这一点?

How can this be done in PowerQuery?

推荐答案

添加栏目.在自定义列公式中键入此单行:

Add column. In custom column formula type this one-liner:

= Text.Select( [Column], {"0".."9"} )

其中 [Column] 是包含数字和其他字符的字符串列.它只提取数字.新列仍然是文本列,因此您必须更改类型.

where [Column] is a string column with a mix of digits and other characters. It extracts numbers only. The new column is still a text column, so you have to change the type.

编辑.如果有点和减号:

= Text.Select( [Column1], {"0".."9", "-", "."} ))

或者,您可以转换现有列:

Alternatively, you can transform the existing column:

= Table.TransformColumns( #"PreviousStepName" , {{"Column", each Text.Select( _ , {"0".."9","-","."} ) }} )

这篇关于仅保留字符串中的数字/删除所有非数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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