Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Printing numerics in a string

1. ## Printing numerics in a string

str="MySalary = \$50,000"

I need fetch all numerics from a string and display them together.

Ex: 50000 in the above case.

-Chandu

2. ## Re: Printing numerics in a string

use split option to get the numeric part as below,

str="MySalary = \$50,000"
n=Split(Str,"\$")
msgBox n(1)

Hope it helps you

3. ## Re: Printing numerics in a string

Yeah. Thanks.
However, I am supposed to get 50,000 without the comma ",".
I was also provided with a clue to use ASC function.

Can u help me in this code?

'''''''''''''''''''''''''''''''''''''''''''''''''' '

str="MySalary = \$50,000"
For i=1 to len(str) step 1
If Asc(Mid(str,i,1))&gt;=48 and Asc(Mid(str,i,1))&lt;=57 then
MyArray = Split(chr(Asc(Mid(str,i,1))),"")
msgbox MyArray(0)
End If
Next

4. ## Re: Printing numerics in a string

coolchandu,

Use the Replace function. An addition to the previous post.

newStr = Replace(msgBox n(1), ",", "")

5. ## Re: Printing numerics in a string

Working fine. Thanks Raj

6. ## Re: Printing numerics in a string

Here's a function I wrote for my framework if it helps:

<font class="small">Code:</font><hr /><pre>
Function StripPriceCharacters(varPrice)
Dim currentLength, currentString
Dim strRight, strLeft
Dim strPrice, intVal

If varPrice = "" Then exit function
currentString = varPrice

'Thir routine will go through each character (left to right), determine if the character is a number
'and if it is it will keep track of the number. This will strip out all of the non digit characters
On error resume next
While currentString &lt;&gt; ""
currentLength = len(currentString) 'track the current string length
strRight = Right(currentString,1) 'get the character on the right
strLeft = ""
strLeft = left(currentString, (currentLength-1)) 'get the remainder of the string exluding the character from the right
err.clear
intVal = cint(strRight) 'check if the character is an integer
If err = 0 Then
strPrice = strRight &amp; strPrice 'if err is not 0 then it worked, so keep track of the number
End If
currentString = ""
currentString = strLeft 'move on with the rest of the string
Wend
On error goto 0

'return the price
StripPriceCharacters = strPrice
End Function
</pre><hr />

7. ## Re: Printing numerics in a string

Try this:

<font class="small">Code:</font><hr /><pre>
Dim str, RegExp, colMatches, ix, returnVal

str= "MySalary = \$50,000"

Set RegExp = New RegExp
RegExp.Global = True
RegExp.Pattern = "\d+"

Set colMatches = RegExp.Execute(str)

For ix = 0 to colMatches.Count - 1
returnVal = returnVal &amp; colMatches(ix)
Next

MsgBox returnVal
</pre><hr />

8. ## Re: Printing numerics in a string

Good one. Thanx

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 9.38%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 08:19 AM.