Search code examples
vbscriptqtphp-uft

Retrieve only numbers and ignore alphabets from String


I have strings like 10A or 20B. I want 10 in 10A or 20 in 20B. How to split only numbers from string using VBScript or QTP internal commands?


Solution

  • I would use a regular expression:

    s = "20B"
    
    Set re = New RegExp
    re.Pattern = "^\d+"
    
    For Each m In re.Execute(s)
      num = CInt(m)
    Next
    
    WScript.Echo num