# Thread: Getting only numerical value from a string

1. ## Getting only numerical value from a string

Hello,
I have a string a="EUR 498", I need to extract just the 498, how do i do it, i tried several options, but of no use.
The EUR may become \$ or abc or anything and "498" may become 1489 or 51432. I just need to extract the numerical part of the string.

Any help is appreciated
Thanks

2. ## Re: Getting only numerical value from a string

split your string at the " " and take the right part of your string

3. ## Re: Getting only numerical value from a string

try this

Msgbox Mid(Trim(a), instr(Trim(a)," ")+1)

Will only work if you always have a space between the type of currency and the value.

4. ## Re: Getting only numerical value from a string

a = EUR 498
Arr = split(trim(a),"")
Arr(0) = EUR
Arr(1) = 498

Hope this helps you out

5. ## Re: Getting only numerical value from a string

A sure shot solution will be
a="EURO 498"
Dim num
For i=1 to len(a)
charat=mid(a,i,1)

if a&gt;="0" and a&lt;="9" then
for j=i to len(a)
if num &gt;="0" and num &lt;="9" the
num=num &amp; mid(a,j,1)
End If
next
Exit for
End If
Next

this will take care of the situation even if there is not a space and also of a currency such as 39\$

Hope this helps

6. ## Re: Getting only numerical value from a string

I use a Filter function for such cases

<font class="small">Code:</font><hr /><pre>
Function FilterStr(ByVal strText, ByVal strCharset, ByVal reverse)
Dim strLen
Dim strChar
strLen = Len(strText)

FilterStr = ""

Dim i

If reverse = False Then
For i = 1 To strLen
strChar = Mid(strText, i, 1)
If InStr(strCharset, strChar) &lt;&gt; 0 Then
FilterStr = FilterStr + strChar
End If
Next
Else
For i = 1 To strLen
strChar = Mid(strText, i, 1)
If InStr(strCharset, strChar) = 0 Then
FilterStr = FilterStr + strChar
End If
Next
End If
End Function
</pre><hr />

<font class="small">Code:</font><hr /><pre>
Msgbox FilterStr("USD 13.42","0123456789.", False)
</pre><hr />

7. ## Re: Getting only numerical value from a string

'' Retrieve numeric part from given String
' @param sString [String] String source to get vumber(s) from
' @return [String] All numeric characters in sequential order &lt;BR&gt;
' or zero length String if there is no any number in given String
' @example ID = GetNumericValue(NameAndIdstring)
' @require If there is several blocks of numeric parts in the string,
' or some single numbers exist there - function will return all of them.
' Use double parsing to avoid any mistake:
' Cut string first using known surrounding points, then retirive number(s)

Function GetNumericValue(sString)
Dim oRegEx, Output
Output = ""
Set oRegEx = New RegExp

oRegEx.Pattern = "[0-9]"
oRegEx.IgnoreCase = True
oRegEx.Global = True

For Each Match in oRegEx.Execute(sString)
Output = Output &amp; Match.Value
Next

GetNumericValue = Output
End Function 'GetNumericValue

Janna

8. ## Re: Getting only numerical value from a string

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.