 
Junior Member
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. 
Moderator
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&Mid(x,i,1)
End If
Next
MsgBox num
Mark Smith. 
Moderator
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&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] 
Senior Member
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 <BR>
' or zero length String if there is no any number in given String
' @remarks MemberID = GetNumericValue(IPaddress)
' @require If there is several blocks of numeric parts in the string,
' or some single numbers exist there  function will return all of them. <BR>
' Use double parsing to avoid any mistake: <BR>
' Cut string first using known surrounding points, then retirive number(s)
Function GetNumericValue(sString)
Dim oRegEx, Output
Output = ""
Set oRegEx = New RegExp
oRegEx.Pattern = "[09]"
oRegEx.IgnoreCase = True
oRegEx.Global = True
For Each Match in oRegEx.Execute(sString)
Output = Output & Match.Value
Next
GetNumericValue = Output
End Function 'GetNumericValue
Janna 
SQA Knight
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: "&cnt&" numbers"
</pre><hr />
But this only works with [any number of] <Space> delimiters between text and numbers. If <Tab> 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

Forum Rules 