如何从alpha数字字符串中仅检索数字(十进制或非十进制) [英] How to retrieve only numbers(decimal or non decimal) from a alpha numericstring

查看:86
本文介绍了如何从alpha数字字符串中仅检索数字(十进制或非十进制)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我只想从字母数字字符串中检索数字。



For例如:



AlphaNum =1.23这是数字



所以这里我只想检索来自AlphaNum的1.23。



感谢您的回复。



问候,

Vinay Kumar。

Hi,

I want to retrieve only the numbers from a alphanumeric string.

For Eg:

AlphaNum = "1.23Here is the number"

so here i want to retrieve only 1.23 from the AlphaNum.

Appreciate for your response.

Regards,
Vinay Kumar.

推荐答案

查看以下帖子:

只有字符串中的数字 [ ^ ]
Have a look on following thread:
Only Numeric In String[^]


有很多方法可以做到这一点,但我可能会使用正则表达式:

There are a number of ways to do this, but I''d probably go with a regex:
\d+\.?\d*|\d*\.?\d+

会找到:

will find:

1
86
23.4

等。或者如果你想要这个数字只是一个开始,那么使用它:

etc. or if you want the number just are the start then use this:

^(\d+\.?\d*|\d*\.?\d+)

哪个将从您的示例中提取1.23部分,但不返回任何内容

Which will extract the 1.23 part from your example, but return nothing for

Here 1.23 is the number


你好,

实际上我没有符合你要求的Vbscript但我有javascript。

如果可以,请检查并将其转换为VBscript。

但是这个脚本肯定会给你想要的输出。



Hello,
Actually i don''t have a Vbscript for your requirement but i have javascript.
Please check it and convert it in VBscript if you can.
but this script surely give you desired output.

var txt = "GUJ 12.50 VAT";
var numb = txt.match(/\d+./g);
numb = numb.join("");
alert(numb);





//你会得到12.50麻木......







请告诉我这对你有用吗?



//You’ll get 12.50 in numb….



Please let me know it is useful for you or not?


这篇关于如何从alpha数字字符串中仅检索数字(十进制或非十进制)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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