# Thread: How can i get the Numbers in The Sentences?

1. ## How can i get the Numbers in The Sentences?

For Example...I have two to Three Lines but it has only 15 is in those lines.How can i seperate the Number from the Texts.

2. ## Re: How can i get the Numbers in The Sentences?

If the numbers are consecutive you can use:

x="There are numbers embeded 999 somewhere in this string"

For i = 1 To Len(x)
num=""
If isNumeric(Mid(x,i,1)) Then
num=num&amp;Mid(x,i,1)
End If
Next

MsgBox num

Mark Smith.

3. ## Re: How can i get the Numbers in The Sentences?

x="There are numbers embeded 999 somewhere in this string"
num=""
For i = 1 To Len(x)
If isNumeric(Mid(x,i,1)) Then
num=num&amp;Mid(x,i,1)
End If
Next

MsgBox num
[img]/images/graemlins/wink.gif[/img] [img]/images/graemlins/wink.gif[/img] [img]/images/graemlins/wink.gif[/img]

4. ## Re: How can i get the Numbers in The Sentences?

'' 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
' @require If there is several blocks of numeric parts in the string,
' or some single numbers exist there - function will return all of them. &lt;BR&gt;
' Use double parsing to avoid any mistake: &lt;BR&gt;
' 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

5. ## Re: How can i get the Numbers in The Sentences?

<font class="small">Code:</font><hr /><pre>
dim str : str="There are 3 numbers 75 in this 999 string"
dim s, cnt : cnt=0
'
for each s in split(str, " ", -1)
if isNumeric(s) then cnt=cnt+1
next
msgBox "str contains: "&amp;cnt&amp;" numbers"
</pre><hr />
But this only works with [any number of] &lt;Space&gt; delimiters between text and numbers. If &lt;Tab&gt; is the only delimiter it will not count correctly.

But jbotosh provides the best solution, as [some form of] regEx is the only way to reliably achieve this task.

#### 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.