Retrieve only numbers and ignore alphabets from St

2019-02-26 23:13发布

问题:

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?

回答1:

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