Separate Numerics From String


Using Len & IsNumeric Funtions

strText = "QTP123Sreenu456Blog"
iLen = Len(strText)
For i=1To iLen
    iChar = Mid(strText,i,1)
    IfIsNumeric(iChar) Then
        strOutput = strOutput & " " & iChar
    EndIf
Next
MsgBox strOutput

Without using any built-in functions

strText = "QTP123Sreenu456Blog"
Set oRegExp = NewRegExp
oRegExp.Pattern = "\d"
oRegExp.Global=True
Set oItems = oRegExp.Execute(strText)
For i=0To oItems.Count-1
    strOutput = strOutput & " " & oItems(i)
Next

For loop above can also be written as below
ForEach oItem In oItems
    strOutput = strOutput & " " & oItem.Value
Next

MsgBox strOutput

No comments:

Post a Comment