Reputation: 1010
Is any simple way to separate second number from this string (number can have too digit):
variable = Test +5 test (1e8+2) 'in this case 1
and assign it to variable2? I tried this code:
temporary = split(variable)
variable2 = temporary(4) 'Now i don't know how to separate i from "(" and "e"
Upvotes: 0
Views: 101
Reputation: 60174
Here's one way using regular expressions to return the 2nd digit (or sequential digits) in a string:
Dim variable As String
Dim variable2 As Long
Dim RE As Object
variable = "Test +5 test (1e8+2)" 'in this case 1
Set RE = CreateObject("vbscript.regexp")
With RE
.Pattern = "\D*\d\D*(\d+).*"
variable2 = .Replace(variable, "$1")
End With
If the first number can also be more than one digit, change the first \d to \d+
Upvotes: 1