Extract a value from mid string
On Tue, 20 Mar 2007 08:14:35 -0700, XP wrote:
Given data like the following:
B.3.54
A.14.1
BC.323.88493
ABC.1.4993
I need to always extract the first value after the first dot (reading left
to right). So, continuing in the example shown, I need to get: 3; 14; 323;
and 1;
This runs on one line at a time so I need to be able to just get one value
at a time copied into a variable. Can someone please post example code that
can do this?
Thanks much in advance.
===============================
Option Explicit
Sub Get2nd()
Dim i As Long
Dim sStr As Variant
Dim oRegExp As Object
Dim colMatches As Object
Set oRegExp = CreateObject("VBScript.RegExp")
sStr = Array("B.3.54", "A.14.1", "BC.323.88493", "ABC.1.4993")
With oRegExp
.IgnoreCase = True
.Global = True
.Pattern = "(\w+\.)(\d+)"
For i = 0 To UBound(sStr)
If .test(sStr(i)) = True Then
Set colMatches = .Execute(sStr(i))
Debug.Print i, colMatches(0).submatches(1)
End If
Next i
End With
End Sub
==================================
--ron
|