How to Search a Numeric value inside a String ? – User friendly Tech help

Hello Automation lovers, during these sweltering summers it is really arduous to share
nsomething with the community. From a long time, I was thinking to share some logic for 
nsearching numbers in a Text.
n
nBy the grace of GOD, today is lucky Day 🙂
n

n

Scenario: – How we can search a Numeric Value inside a given Text/String/File?
n
nSolution:-

n

Note: – Please refer the link on RegularExpression Object for more understanding of the
n code.

n

'*******************************************Sub***************************************************
'Function Name:- fn_SearchNumeric
'Function Description:- Used to find the Numeric values inside a string
'Input Parameters:- Sting
'Output Parameters:- Final Search Message
'Created By :- www.uftHelp.com
'Date:- 19th June,2014
'****************************************************************************************************
msgbox fn_SearchNumeric("Please search 89766 Numeric values")
Function fn_SearchNumeric(strSearchString)
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Global = True
'Regular Expression to search Numeric values
objRegExp.Pattern = "d"
Set objMatches = objRegExp.Execute(strSearchString)
'Incase match is found
If objMatches.Count > 0 Then
strMessage = "The given string '"&strSearchString&"'
has the following numeric values:-" & vbCrlf
iNumeric = ""
For Each sMatch in objMatches
iNumeric = iNumeric & sMatch.Value
Next
fn_SearchNumeric = strMessage & iNumeric
Else
fn_SearchNumeric = "Sorry No match found!!Please correct
the String to search"
End If
End Function
Was this article helpful?
YesNo

Similar Posts