Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted

Have a look on following thread:
Only Numeric In String[^]
 
Share this answer
 
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+)
Which will extract the 1.23 part from your example, but return nothing for
Here 1.23 is the number
 
Share this answer
 
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.

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


//You’ll get 12.50 in numb….



Please let me know it is useful for you or not?
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900